How can I introduce multiple conditions in LIKE operator?
Here is an alternative way:
select * from tbl where col like 'ABC%'
union
select * from tbl where col like 'XYZ%'
union
select * from tbl where col like 'PQR%';
Here is the test code to verify:
create table tbl (col varchar(255));
insert into tbl (col) values ('ABCDEFG'), ('HIJKLMNO'), ('PQRSTUVW'), ('XYZ');
select * from tbl where col like 'ABC%'
union
select * from tbl where col like 'XYZ%'
union
select * from tbl where col like 'PQR%';
+----------+
| col |
+----------+
| ABCDEFG |
| XYZ |
| PQRSTUVW |
+----------+
3 rows in set (0.00 sec)
Can the NOT operator work on multiple conditions present in parenthesis?
You got bitten by operator priority. Parentheses are your friend, you see.
WHERE NOT Country='Germany' AND NOT Country='USA';
actually means, since NOT has precedence over AND:
WHERE (NOT Country='Germany') AND (NOT Country='USA');
Since "NOT a=b" is "a!=b", this means:
WHERE Country!='Germany' AND Country!='USA';
which, as the others pointed out, looks muuuuch better like this:
WHERE Country NOT IN ('Germany', 'USA');
Now, next topic. This one:
WHERE NOT (Country='Germany' AND Country='USA');
Country can not be Germany and USA at the same time, so the stuff inside the () is always FALSE, so this equates to:
WHERE NOT (FALSE);
i.e.
WHERE TRUE;
ie, you get your whole table.
Related Topics
Required to Join 2 Tables With Their Fks in a 3Rd Table
How to Join Multiple SQL Tables Using the Ids
Where Is |Datadirectory| Defined
Get Record Counts For All Tables in MySQL Database
SQL Update Set One Column to Be Equal to a Value in a Related Table Referenced by a Different Column
Using Stored Procedure in Classical Asp .. Execute and Get Results
Why Does MySQL Report a Syntax Error on Full Outer Join
How to Print Varchar(Max) Using Print Statement
Difference Between Natural Join and Inner Join
Pivot Rows to Columns Without Aggregate
Optimise Postgresql For Fast Testing
Are There Any Disadvantages to Always Using Nvarchar(Max)
Why No Windowed Functions in Where Clauses
Difference Between Primary Key and Unique Key
Delete Column from Sqlite Table
Mixing Ansi 1992 Joins and Commas in a Query
Humanized or Natural Number Sorting of Mixed Word-And-Number Strings