2

What does it mean to say;

select col1,col2 from table1 join table2 on 1=1 where table2.status = '1'
Victor
  • 16,609
  • 71
  • 229
  • 409
  • 2
    Means the original dev likes writing obscure queries. – rsenna Apr 01 '11 at 21:12
  • Check here : [In Oracle, is starting the SQL Query's WHERE clause with 1=1 useful?](http://stackoverflow.com/questions/1069373/in-oracle-is-starting-the-sql-querys-where-clause-with-1-1-useful) – Saurabh Gokhale Apr 04 '11 at 03:00

2 Answers2

1

Looks like a cross join to me.

Otávio Décio
  • 73,752
  • 17
  • 161
  • 228
1

Sometimes I see predicates like "1=1" in queries generated by a tool.

The pseudocode for the tool would be something like:

sql := sql || '1=1';
FOR i IN 1 .. predicates.COUNT LOOP
  sql := sql || ' AND ' || predicates(i);
END LOOP

This way, it doesn't have to worry about omitting the "AND" for the first predicate.

Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158