Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

I've been curious. What are the differences between these respective queries:

1. SELECT * FROM `tablename`

2. SELECT * FROM `tablename` WHERE 1

3. SELECT * FROM `tablename` WHERE 1=1

1 Answer

0 votes
by (40.4k points)

Query 2 and Query 3(i.e. SELECT * FROM `tablename` WHERE 1 and SELECT * FROM `tablename` WHERE 1=1) mentioned in the question are the same in MySQL. 

Functionally, if you see Query 1 i.e.(SELECT * FROM `tablename`) is also the same. 

'WHERE 1' syntax is not standard therefore, it will not work in other dialects.

We can add 'WHERE 1' or 'WHERE 1 = 1' syntax hence, because WHERE conditions can be easily added or removed to/from a query by adding in/commenting out some "and ..." components like this:

SELECT * 

FROM `tablename` WHERE 1=1

--AND Column1 = 'Value1'

AND Column2 = 'Value2'

Related questions

0 votes
1 answer
asked Dec 12, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 29, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...