Shoutbox

Why wont this mySQL query wont work? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Why wont this mySQL query wont work? (/showthread.php?tid=50498)

Why wont this mySQL query wont work? by Mike on 09-14-2005 at 07:08 PM

code:
SELECT MAX(ID), `artist`, `title` FROM `historylist`

It says:
quote:
Originally posted by mySQL Error
#1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

I tried doing something like that:
code:
SELECT MAX(ID), `artist`, `title` FROM `historylist` GROUP BY `ID`
but it didnt just show that Max(ID), it also showed other IDs, with wrong artists and titles...

Anyone help please? :)

Thanks.
RE: Why wont this mySQL query wont work? by wj on 09-14-2005 at 08:24 PM

SELECT `ID`, `artist`, `title` FROM `historylist` WHERE  ID IN (SELECT max(ID) FROM historylist)

That should do ya.


RE: Why wont this mySQL query wont work? by RaceProUK on 09-14-2005 at 08:26 PM

SELECT `ID`, `artist`, `title`
FROM `historylist`
WHERE `ID` = SELECT MAX(ID) FROM `historylist`;

Embedded SELECTs rock!

Edit:

quote:
Originally posted by wj
SELECT `ID`, `artist`, `title` FROM `historylist` WHERE  ID IN (SELECT max(ID) FROM `historylist`);
should also work.
RE: Why wont this mySQL query wont work? by Mike on 09-15-2005 at 09:18 AM

Thanks for your help [Image: msn_happy.gif]

optiz0r from IRC helped me too.

He gave me this code:

code:
SELECT  `artist` ,  `title`
FROM  `historylist`
ORDER  BY  `ID`  DESC
LIMIT 1
which also works [Image: msn_happy.gif]