0

I've tried Googling this but couldn't find anything. When I run the query below, it outputs 4 identical rows. So I want to use the DISTINCT keyword to eliminate the duplicates. But I get an SQL error when I run the query. Remove the DISTINCT and it works fine.

SELECT DISTINCT list.`id`, * 
FROM `listings` list 
INNER JOIN `selections` sel
ON list.`id` = sel.`lid` 
WHERE 1 AND `activity` = 'running' 
AND ( 0 OR (sel.`parent` = 
'1') OR (sel.`parent` = '2') )
4

1 Answer 1

1
SELECT DISTINCT columns.you
              , actually.want
           FROM listings l
           JOIN selections s
             ON l.id = s.lid 
          WHERE activity = 'running' 
            AND s.parent IN(1,2)
Sign up to request clarification or add additional context in comments.

5 Comments

Where do I put the DISTINCT then? SELECT DISTINCT id, title, address ?
@TheHawk DISTINCT is put first.. it applies to all of the fields.. you shouldn't select a column then * like you did in your query. thats not valid syntax for MySQL regardless.
@JohnRuddell hit the nail. The misunderstanding is thinking that distinct id, * only affects id. It affects the * as well.
@paqogomez DISTINCT id, * is not valid syntax in MySQL, so if the OP is using MySQL that wouldn't work. unless it was specified... something like SELECT DISTINCT s.id, l.*
as is a lot of Strawberries comments ;) many are helpful though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.