| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

02-09-12, 17:12
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 11
|
|
Can't create a view in Navicat for MySQL
|
|
I am trying to create a view using Navicat for MySQL. My query is fine and works perfectly when I run it as simply a query. When I try to create a view out of this query, I get an error message telling me that I have a "select" statement in my "from" clause. This is true, but I get no errors when I run the query alone. The error message also neglects to tell me why it's so bad that I have a select statement in my from clause. Is anyone knowledgeable with this that can help me, please?
|
|

02-09-12, 17:47
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
please show the CREATE VIEW statement, and the exact error message
|
|

02-10-12, 16:13
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 11
|
|
|
|
Quote:
Originally Posted by r937
please show the CREATE VIEW statement, and the exact error message
|
The Error Code was exactly: 1349 - View's SELECT contains a subquery in the FROM clause.
I didn't use a CREATE VIEW statement, but rather used the GUI.
|
|

02-10-12, 16:17
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
oh, okay
at this point i'd be inclined to blame navicat
:wink: 
|
|

02-10-12, 16:29
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 11
|
|
Quote:
Originally Posted by r937
oh, okay
at this point i'd be inclined to blame navicat
:wink: 
|
I just tried on the mysql console and received the same error message. Here is the code that was run:
Code:
CREATE VIEW Prod_Code_Status AS
(
select MDProdCode, ARName, RAAMSID, ARID, PropService, Location_ID, Address, City, State, ZIP, Service, Snapshot_Month, Team_Status
, CASE WHEN Team_Status = 'down'
THEN ( SELECT CAST(max(Going_Down) AS CHAR)
FROM MarketDataInventoryReport
WHERE MDProdCode = this.MDProdCode and Snapshot_Month = this.Snapshot_Month and ARName = this.ARName and PropService = this.PropService and Location_ID = this.Location_ID and Service = this.Service limit 1)
ELSE '' END AS The_Date
From (select MDProdCode, ARName, RAAMSID, ARID, PropService, Location_ID,Address, City, State, ZIP,Service, Snapshot_Month
, case when max(Current_Month) = 'up'
THEN 'up'
ELSE 'down' END AS Team_Status
from MarketDataInventoryReport
where MDProdCode<>'' and MDProdCode<>'N/A' and MDProdCode is not null
group by MDProdCode, ARName, PropService, Location_ID, Snapshot_Month order by Snapshot_Month, MDProdCode, ARName, PropService, Location_ID) as this;
)
|
|

02-10-12, 16:36
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 11
|
|
I've heard a way around this is to create a view of the of the forbidden "FROM" clause and use that. Does that make any sense?
|
|

02-10-12, 22:28
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
yep, makes sense
Code:
CREATE VIEW my_forbidden_FROM_clause AS
SELECT MDProdCode
, ARName
, RAAMSID
, ARID
, PropService
, Location_ID
, Address
, City
, State
, ZIP
, Service
, Snapshot_Month
, CASE WHEN MAX(Current_Month) = 'up'
THEN 'up'
ELSE 'down' END AS Team_Status
FROM MarketDataInventoryReport
WHERE MDProdCode <> ''
AND MDProdCode <> 'N/A'
AND MDProdCode IS NOT NULL
GROUP
BY MDProdCode
, ARName
, PropService
, Location_ID
, Snapshot_Month
and then
Code:
CREATE VIEW Prod_Code_Status AS
SELECT MDProdCode
, ARName
, RAAMSID
, ARID
, PropService
, Location_ID
, Address
, City
, State
, ZIP
, Service
, Snapshot_Month
, Team_Status
, CASE WHEN Team_Status = 'down'
THEN ( SELECT CAST(MAX(Going_Down) AS CHAR)
FROM MarketDataInventoryReport
WHERE MDProdCode = this.MDProdCode
and Snapshot_Month = this.Snapshot_Month
and ARName = this.ARName
and PropService = this.PropService
and Location_ID = this.Location_ID
and Service = this.Service )
ELSE '' END AS The_Date
FROM my_forbidden_FROM_clause AS this
|
|

02-14-12, 14:00
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 11
|
|
Thanks
Once again, you've saved my life.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|