Jump to content

Select max subquery


dhipp

Recommended Posts

I'm not sure why this query is not working on MySql 5.0.24 as it works on MySql 4.1.14.  I am trying to create a simple subquery as:

 

SELECT a.login_id

FROM disco_vendor_ids a

WHERE a.vendor = 'XYZ'

AND a.effdt = (SELECT max(b.effdt)

FROM disco_vendor_ids b

WHERE a.vend_id = b.vend_id)

 

When I try to run this query in 5.0.24 I keep getting:

#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT max(b.effdt)

FROM disco_vendor_ids b

WHERE a.vend_id ...

 

I don't think it's a syntax error as the query runs in 4.1.14.  I have only recently set this database up in 5.0.24 perhaps there is a setting somewhere that is not correct?  Any help would be greatly appreciated.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/62583-select-max-subquery/
Share on other sites

clearstatcache - The table structure is:

 

Table name: disco_vendor_ids

 

Field      Type

-------    -----

vend_id  int(5)

effdt      date

vendor    varchar(15)

descr      varchar(35)

login_id    varchar(30)

passwd    varchar(30)

 

 

I think there might be difference between MySql 4.1.14 and 5.0.24 and the way queries are parsed?  I'm not sure what "features" were added for 5.0.24, but the subquery worked in 4.1.14.  Thanks for your help so far.

Link to comment
https://forums.phpfreaks.com/topic/62583-select-max-subquery/#findComment-311743
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.