Reputation: 145
I am trying to get this query to only display 1 result (not LIMIT) in this example:
SELECT company_id FROM `location` WHERE `state` = 'XX'
It results are similar to this:
16 9 9 9 9 30 30 30 45 50 50 50 50 57 7 79 80 80 80 80 120 120 120 120 120 128 131 120 265 265
I am aiming for these results:
16 9 30 45 50 57 7 79 80 120 128 131 120 265
Upvotes: 0
Views: 94
Reputation: 2008
Use DISTINCT
keyword
SELECT DISTINCT company_id FROM `location` WHERE `state` = 'XX'
It will give the desired result.
Upvotes: 1
Reputation: 16310
Simply use DISTINCT
when you want to retrieve distinct result set.....
SELECT DISTINCT company_id FROM `location` WHERE `state` = 'XX'
You can use Group By
as an alternative to DISTINCT in following way:
SELECT company_id FROM `location` WHERE `state` = 'XX' GROUP BY company_id
The DISTINCT
and GROUP BY
generates same execution plan as performance wise though I strongly recommend you to use DISTINCT
in your scenario......
Upvotes: 0