1

I am using the OR operator in the following fashion:

SELECT * FROM Customers
WHERE City = "Berlin" OR City = "London"

The above returns a results table containing some data, however what also returns data is:

SELECT * FROM Customers
Where City = "Berlin" OR "London"

I am using a questionable SQL editor currently, and want to know if this would be valid in a MySQL environment.

Kobi
  • 135,331
  • 41
  • 252
  • 292

5 Answers5

1

You are looking for

SELECT * FROM Customers Where City IN('Berlin', 'London');

The query:

Where City='Berlin' OR 'London'

Applies the logical OR operator (||), so OR "London" is equivalent to OR 0, and Where City = 'Berlin' OR 0; will just return 'Berlin'

SqlFiddle here with truth table here

Minor, but you should look at using single quotes for string literals, as this is more portable between RDBMS's and use of " will depend on ANSI QUOTES.

Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285
0

Well, if it valid in SQL, it should be valid in MySQL to. Are you wondering if this would be valid in MYSQL

SELECT * FROM Customers Where City="Berlin" OR"London"

It should be valid in MySQL

Hope that helps. If it does not, add a comment

mfredy
  • 597
  • 1
  • 8
  • 16
0

this returnd the same values as your first sql-string.

But your first string is more readable for others.

Snickbrack
  • 1,253
  • 4
  • 21
  • 56
0

You can use IN

SELECT * 
FROM Customers
Where City IN ("Berlin","London")
Milen
  • 8,697
  • 7
  • 43
  • 57
0

Well, Cassini i have check your syntax and run this query on my table i did not getting same result. I am getting correct output as expected.

i have run this command:

SELECT * FROM `city` where name = 'London' or 'Berlin'

and i got only london in name column. When i run this command:

SELECT * FROM `city` where name = 'London' or name = 'Berlin'

then i got both the cities in name column. so command is valid it will return only valid output which satisfy the condition.

So, i can say that command is valid but execute only that part of query which satisfy MYSQL Select syntax.

Manoj Sharma
  • 596
  • 1
  • 6
  • 23