Conditional GROUP BY - MySQL 4.1
Posted: Mon Apr 16, 2007 1:22 am
Is it possible to have GROUP BY on one column conditionaly?
I have a table where i keep all the bids details. I want to list only one bid for a user.
Table Structure
------------------------------
auto_id - auto increment
userid - registered user int id
email - if the bidder is not a registered user, he/she can bid by supplying email
If i use this query, it will list only one bid for each registered member but at the same time only one bid for all non-registered members' bids.
Is it possible if userid is >0 GROUP on userid otherwise on email
OR
GROUP BY on userid if userid>0 and list all the other records where userid=0
I am using MySQL 4.1.
I have a table where i keep all the bids details. I want to list only one bid for a user.
Table Structure
------------------------------
auto_id - auto increment
userid - registered user int id
email - if the bidder is not a registered user, he/she can bid by supplying email
If i use this query, it will list only one bid for each registered member but at the same time only one bid for all non-registered members' bids.
Code: Select all
SELECT auto_id, userid, email FROM bids GROUP BY useridOR
GROUP BY on userid if userid>0 and list all the other records where userid=0
I am using MySQL 4.1.