skip to Main Content

I wanted to run a query where I will get all the fields where one field is unique.I tried this

Select * from announcements where title = SELECT distinct title 
FROM announcements;

But it’s not working. Can anyone please help me out here.

4

Answers


  1. Chosen as BEST ANSWER

    Thanks all. I got what I was looking for

    SELECT MIN( id ) AS id, title, issue_date, expirty_date, is_active FROM announcements GROUP BY title ORDER BY issue_date DESC
    

  2. Select * 
      from announcements 
     where title in (SELECT distinct title 
    FROM announcements)
    
    Login or Signup to reply.
  3. This query:

    select title 
    from announcements 
    group by title 
    having count(*) = 1
    

    returns all the unique titles.
    Use it with the operator IN:

    select * from announcements 
    where title in (
      select title 
      from announcements 
      group by title 
      having count(*) = 1
    )
    
    Login or Signup to reply.
  4. Try use round brackets

    Like:
    Select * from announcements where title in (SELECT distinct title
    FROM announcements);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search