Re: syntax question
| From: | marco@behnke.biz | Date: | Tue, 07 Feb 2012 15:46:35 +0000 |
| Subject: | Re: syntax question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316526@lists.php.net to get a copy of this message | ||
admin@buskirkgraphics.com 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‘”
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.¨k×
> _Ö‡u¯i\†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@behnke.biz
Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal
http://www.behnke.biz