I have table like this
-------------------------------------------------------------------
id | title | image | name |
-------------------------------------------------------------------
1 | xyzab | so.jpg | googl |
2 | acbde | am.jpg | artic |
3 | xyzab | pp.jpg | other |
i want to select unique or distinct title with it's image and name also. DO not want to repeat the values. I use this this code
SELECT DISTINCT title,image,name,id FROM `some_table`
but this is not working fine
NOTE: The OP is working with MySQL
Using DISTINCT will ensure no 2 records have all columns matching, so this is working correctly.
If you want to return unique titles, you need to decide what image and name would be returned.
You could use a group by with an aggregate function to do this. For example:
SELECT title, MIN(image), MIN(name), MIN(id)
FROM `some_table`
GROUP BY title
But it depends on what results you are after...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With