Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subselects don't work

Status
Not open for further replies.

rastkocvetkovic

Programmer
Aug 11, 2002
63
SI
Hello!

I'm experiencing a problem on Apache (1.3.26) + mySQL (3.23.39) + PHP (4.2.2).

The following SQL statement...
SELECT id FROM News WHERE id = (SELECT MAX(id) FROM News)

...returns an error saying:

You have an error in your SQL syntax near 'SELECT MAX(id) FROM News)' at line 1

In the mySQL documentation it says that SUBSELECTS work without any problem. Is there anything I can do? Thank you for your help!

Rastko
 
isn't it supposed to be in '?
(SELECT MAX('id') FROM News)

Rick
 
ristmo2001,
actually the problem isn't SELECT MAX(id) FROM News, but the SUBSELECT itself (because SELECT MAX works fine if I exec it itself).
The following syntax also reports a similar error:

SELECT *
FROM Options
WHERE id NOT IN (SELECT options_id FROM settings WHERE User = 1)

Thank you for following posts!
 
What about this?
SELECT id FROM News WHERE id = '(SELECT MAX(id) FROM News)'

I might be wrong, but it just seems like there are some '' missing.

Rick
 
ristmo2001,
nope, still getting (even more) errors :)

I hope somebody (maybe even we) will find the solution ASAP.

Let's go on programming.

Rastko
 
I thought subselects was MySQL 4.x only?
A quote from the MySQL documentation:
[tt]1.7.4.1 SubSELECTs

MySQL Server currently only supports nested queries of the form INSERT ... SELECT ... and REPLACE ... SELECT .... You can, however, use the function IN() in other contexts. Subselects are currently being implemented in the 4.1 development tree. [/tt]
//Daniel
 
I'm with Daniel on this, Subselects are mysql 4xx only. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Yep, we've come to the conclusion that subselects are in coming in 4.x only! Thanks folks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top