Is โ€œSelectโ€ from table 1, table 2 a valid query?

Sql query is valid or not. I was asked about this in an interview?

+4
source share
3 answers

Well, the request you are writing is not a valid request:

Select * from table 1, table 2 

Numbers are not allowed as table aliases. In many databases, you can:

 select * from table "1", table "2" 

If you want numeric aliases.

If you did not expect a space before "1" and "2", the query is equivalent to:

 select * from table1 cross join table2 

Perfectly acceptable, but the cross join syntax is much preferable.

+2
source

This is a valid query - it produces the Cartesian product of two tables. This is equivalent to this query in ANSI SQL syntax:

 select * from table1 join table2 on 1=1 

The usefulness of this request is very controversial.

Here is the daemon on SQLFiddle .

+5
source

It depends on which database you are using.

It has been valid SQL for a long time, but some recent versions of SQL Server, for example, discard the syntax in favor of using the join keyword.

0
source

All Articles