1

Hi im obtaining data from a table through a query.. i need to omit some of the data types, currently i cant write the query for that

+--------+----------------------+-----------+----------------+
| aut_id | aut_name             | country   | home_city      |
+--------+----------------------+-----------+----------------+
| AUT001 | William Norton       | UK        | Cambridge      |
| AUT002 | William Maugham      | Canada    | Toronto        |
| AUT003 | William Anthony      | UK        | Leeds          |
| AUT004 | S.B.Swaminathan      | India     | Bangalore      |
| AUT005 | Thomas Morgan        | Germany   | Arnsberg       |
| AUT006 | Thomas Merton        | USA       | New York       |
| AUT007 | Piers Gibson         | UK        | London         |
| AUT008 | Nikolai Dewey        | USA       | Atlanta        |
| AUT009 | Marquis de Ellis     | Brazil    | Rio De Janerio |
| AUT010 | Joseph Milton        | USA       | Houston        |
| AUT011 | John Betjeman Hunter | Australia | Sydney         |
| AUT012 | Evan Hayek           | chillie   | Chillie        |
| AUT013 | E. Howard            | Spain     | Madrid         |
| AUT014 | C. J. Wilde          | UK        | London         |
| AUT015 | Butler Andre         | Austria   | Florida        |
+--------+----------------------+-----------+----------------+

i want to omit brazil, australia and chillie.. i tried query similer to below but it dint work

SELECT d.country, COUNT(*) AS number FROM ..............
 AND d.country NOT LIKE 'brazil' OR 'Austria' OR 'Chillie'
 GROUP BY d.country

but it works for one country like this

SELECT d.country, COUNT(*) AS number FROM ..............
 AND d.country NOT LIKE 'brazil'
 GROUP BY d.country

can anybody help me to do the filtering and get rid of the terms i want

1
  • Thanks for all the useful replies guys!!! Commented Sep 14, 2015 at 11:06

5 Answers 5

1

Use NOT IN:

SELECT d.country, COUNT(*) AS number FROM ..............
 AND d.country NOT IN ('brazil', 'Austria', 'Chillie')
 GROUP BY d.country
Sign up to request clarification or add additional context in comments.

Comments

1

NOT IN will work for you:

SELECT d.country, COUNT(*) AS number FROM tbl
 where d.country NOT in ('brazil','Austria','Chillie')
 GROUP BY d.country

Comments

1
SELECT d.country, COUNT(*) AS number FROM ..............
AND d.country NOT IN ('brazil', 'Austria', 'Chillie')
GROUP BY d.country

Comments

1

You can achive using AND

 SELECT d.country, COUNT(*) AS number FROM ..............
 AND d.country <> 'brazil' AND d.country <>'Austria' AND d.country <>'Chillie'
 GROUP BY d.country

OR NOT IN

 SELECT d.country, COUNT(*) AS number FROM ..............
 AND d.country NOT IN ('brazil','Austria','Chillie')
 GROUP BY d.country

Comments

1

Do this... [edit]

 SELECT d.country, COUNT(*) AS number FROM ..............
     AND d.country NOT LIKE 'brazil' AND d.country NOT LIKE 'Austria' AND d.country NOT LIKE 'Chillie'
     GROUP BY d.country;

Above works but other people answers are best...!

1 Comment

But this query is WRONG! It should be AND all the way, not OR d.country NOT LIKE 'Chillie'.

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.