Kapaacius
Kapaacius

Reputation: 715

Exclude result from MySql query

I have a Select query something like this

SELECT * FROM table WHERE id = ?

I need a condition to it which excludes a specific result. if(type = 'tv' and that type's code = '123') then exclude that row from select result. Since my SQL skills are not very strong, I am not sure how to make that happen.

Upvotes: 1

Views: 20783

Answers (4)

Akhil
Akhil

Reputation: 2602

SELECT * FROM table WHERE  id = ? AND not(type = 'tv' and code = '123')

Is this what you looking for?

There is a difference between type <> 'tv' and code <> '123' and not(type = 'tv' and code = '123')

Upvotes: 8

echo_Me
echo_Me

Reputation: 37233

try this

     SELECT * FROM table WHERE  id = ? and (type <> 'tv' or code <> 123)

Upvotes: 0

Vishal R
Vishal R

Reputation: 1074

Below is a sample query for your problem. If your table has coloum names as - type (VARCHAR or VARCHAR2 or CHAR) and code (VARCHAR or VARCHAR2 or CHAR)

SELECT * FROM <table-name> WHERE type NOT IN ('tv') AND code NOT IN ('123');

Upvotes: 0

Sylvain Leroux
Sylvain Leroux

Reputation: 51980

select *  from tbl where id = 1 and (type <> "abc" or code <> "123");

See http://sqlfiddle.com/#!2/7dc49/2

Upvotes: 0

Related Questions