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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with subquery! 1

Status
Not open for further replies.

borgrulze

Programmer
Apr 4, 2002
11
0
0
IN
i need some help with is query.

SELECT * FROM pollquestions WHERE timeinserted=(select max(timeinserted) from pollquestions);

the inner query, select max(timeinserted) from pollquestions, works fine but gives an error when used with the outer query.

timeinserted is of type datetime.
 
Unfortunately, sub-queries are not supported by MySQL until version 4.1 (currently alpha).

If you only want the most recent record, you could simply use:[tt]
SELECT * FROM pollquestions ORDER BY timeinserted DESC LIMIT 1;[/tt]


If you want all matching records, then the simplest way I can think of is to use two queries:[tt]
SELECT @d:=MAX(dateinserted) FROM pollquestions;
SELECT * FROM pollquestions WHERE timeinserted=@d;[/tt]


-----
ALTER world DROP injustice, ADD peace;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top