Separating a subquery
Im a newbie and dont know how to separate the below SQLpc string into 2 separate statements.
I have about 5 of these statements in an ASP page for a poll im trying to get working.
Im using MySQL 4.0.18 which apparently doesnt support nested queries. I get a 1064 ERROR.
Can anyone help?
Dim SelMax, ConnPoll, SQLpc, RSpc
Set ConnPoll = Server.CreateObject("ADODB.Connection")
ConnPoll.Open "driver= ###path to my DB###"
SQLpc = "SELECT * FROM pollcount WHERE ID = (SELECT MAX(ID) FROM pollcount)"
Set RSpc = ConnPoll.Execute(SQLpc)
SELECT * FROM pollcount ORDER BY ID DESC LIMIT 1
returns the record with maximal ID
thx stereofrog..dat worked good.
However upon reading other mysql statements in the ASP page, i found they were getting the the ID from another table.
sqlq = "Select * from ques WHERE ID = (Select MAX(ID) From pollcount)"
Do i simply add 2nd table ahead of ID like below?
SELECT * FROM ques ORDER BY pollcount.ID DESC LIMIT 1
No, I'm afraid it doesn't work this way, you'll need JOIN here. See Rewriting Subqueries as Joins in mysql manual.
If have lots of subqueries like this, consider upgrading to mysql 4.1.