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.

 
Go Back  dBforums > Database Server Software > MySQL > View with From in subquery

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-16-08, 18:02
jacsoft jacsoft is offline
Registered User
 
Join Date: Jan 2006
Posts: 17
View with From in subquery

I have a query from which I want to turn into a view:

SELECT * FROM `telefoonnummers`
WHERE `Afdeling` IN
(SELECT `Afdeling`
FROM
(
SELECT @a:=@a+1 as 'a'
,`Afdeling`
FROM `Afdeling-telefoon`
JOIN (SELECT @a:=0) x
ORDER BY `Afdeling`
) y WHERE mod(a,2) = 0) ORDER BY `Afdeling`, `Naam`

The only problem is I cant make a view out of this. It says it is not possible.

It returns:
#1349 - View's SELECT contains a subquery in the FROM clause

Any ideas how I could turn this into a view (or stored procedure maybe)?
Reply With Quote
  #2 (permalink)  
Old 03-23-08, 12:05
digioz digioz is offline
Registered User
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 34
Quote:
Originally Posted by jacsoft
I have a query from which I want to turn into a view:

SELECT * FROM `telefoonnummers`
WHERE `Afdeling` IN
(SELECT `Afdeling`
FROM
(
SELECT @a:=@a+1 as 'a'
,`Afdeling`
FROM `Afdeling-telefoon`
JOIN (SELECT @a:=0) x
ORDER BY `Afdeling`
) y WHERE mod(a,2) = 0) ORDER BY `Afdeling`, `Naam`

The only problem is I cant make a view out of this. It says it is not possible.

It returns:
#1349 - View's SELECT contains a subquery in the FROM clause

Any ideas how I could turn this into a view (or stored procedure maybe)?
Instead of turning it into a view, turn it into a stored procedure (MySQL 5.0.0 or higher). It can still return the resultset you want to see, and it shouldn't complain about the subquery.
__________________
DigiOz Multimedia
http://www.digioz.com
Reply With Quote
  #3 (permalink)  
Old 03-23-08, 13:18
jacsoft jacsoft is offline
Registered User
 
Join Date: Jan 2006
Posts: 17
I use MySQL > 5 so stored procedures shouldn't be a problem. The only problem is that I don't know whether the application that I use which requires this query is capable of calling a Stored procedure instead of a query, so therefore I rather use a view/query.
Reply With Quote
  #4 (permalink)  
Old 03-23-08, 17:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
could you explain in words what the "application that I use which requires this query" expects to see

what is that stuff with the variable and the mod function and all that?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-23-08, 19:02
digioz digioz is offline
Registered User
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 34
Quote:
Originally Posted by jacsoft
I use MySQL > 5 so stored procedures shouldn't be a problem. The only problem is that I don't know whether the application that I use which requires this query is capable of calling a Stored procedure instead of a query, so therefore I rather use a view/query.
If you are using a .NET application I can tell from experience that calling a stored procedure is not a problem. Unless you are using some other type of application, in which case I would have to ask what it is.
__________________
DigiOz Multimedia
http://www.digioz.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On