Reputation: 2405
Currently I have this query:
SELECT column1,column2 FROM table
column1 needs to be distinct, column2 does not.
SELECT DISTINCT column1, NON-DISTINCT column2 FROM table
Now I know that doesn't make sense but I need column1 to be distinct and column2 to be anything. How would I do that.
Upvotes: 0
Views: 2564
Reputation: 2218
Try this (fastest):
SELECT *
FROM `table`
GROUP BY pid
HAVING min( id )
second (slower) option:
select *
from `table` t1
where
t1.id = (select min(id) from `table` t2 where t1.pid = t2.pid)
Upvotes: 1
Reputation: 20456
select pid, group_concat(distinct bla1) as bla1s
from table
group by pid;
The above will get you 1 row for each pid and you'll be able to see if there are extra bla1s without introducing a new column or having to settle for a random choice of multiple bla1s.
Upvotes: 2