mysql distinct etc
- Started
- Last post
- 4 Responses
- mikotondria3
ah, so I have some entries mysql table that have the same 'title', but different other data - Im trying to do a select whereby I list the whole table, and all fields, but only show one of each same-named item, something like..
SELECT DISTINCT name, * FROM my_table..
but this is not working.
Any pointers ?
- acescence0
SELECT DISTINCT (name), other_col, another_col FROM my_table
- mikotondria30
bah, would you believe it - that doesnt work : /
- acescence0
oh, sorry misunderstood. that will give you all rows with unique combos, not unique on just that one field. that's a little more tricky...
SELECT *, COUNT(name) FROM my_table GROUP BY name HAVING COUNT(name)>=1;
- mikotondria30
Thats awesome, thanks acescence, I owe you one :).
ended up as:SELECT *, COUNT(title) FROM my_table WHERE status='active' AND title REGEXP '^s' GROUP BY title HAVING COUNT(title)>=1 ORDER BY title ASC