admin@xxxxxxxxxxxxxxxxxxx hat am 7. Februar 2012 um 15:11 geschrieben: > I have been struggling with this issue for an hour and honestly I am not > sure why. > > I consider myself to be pretty savvy with MySQL but I am running into an > syntax error that is just flat out eluding me. > > > > $query = "SELECT `table2`.`name` from `table1` ,`table2` WHERE > `table2`.`user_id`=`table1`.`seller_id` AND IF(`table2`.`name`='juice','No > Juice for YOU', `table2`.`name`=`table2`.`name`) LIMIT 1"; > > This query works!! > > > > But If I try to add a GROUP BY to the query, complete failure. > > $query = "SELECT `table2`.`name` FROM `table1` ,`table2` WHERE > `table2`.`user_id`=`table1`.`seller_id` AND IF(`table2`.`name`='juice','No > Juice for YOU', `table2`.`name`=`table2`.`name`) GROUP BY `table1`.`ID` > LIMIT 1"; This is a nice query but I am not sure if I understand what you want to do? Maybe we could start with your error message and a table structure :-) That would be handy. You wanna get all users that have at least on sell? But only once? Maybe something like that? SELECT table2.name FROM table2, (SELECT seller_id FROM table1 GROUP BY seller_id) as table1 WHERE table2.user_id = table1.seller_id AND IF(table2.name = 'juice','No Juice for YOU', table2.name = table2.name) ; Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: marco@xxxxxxxxxx Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php