Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT from nothing?

Tags:

sql

Is it possible to have a statement like

SELECT "Hello world" WHERE 1 = 1 

in SQL?

The main thing I want to know, is can I SELECT from nothing, ie not have a FROM clause.

like image 466
Ritwik Bose Avatar asked Sep 17 '10 03:09

Ritwik Bose


People also ask

Can we use SELECT without from?

select without from , on the other hand, works on four of them. By now you might wonder why stand-alone values might be useful at all. As I implied above, it is more powerful than select without from because it is not limited to produce a single row. With select without from , you'd need to use union .

How do I SELECT nothing in MySQL?

SELECT NONE FROM TABLE WHERE password="abc". SELECT NULL AS X FROM TABLE WHERE password="abc". would work in SQL Server. X would be typed as int .

What is nothing in SQL?

The NULL statement is an executable statement that does nothing. The NULL statement can act as a placeholder whenever an executable statement is required, but no SQL operation is wanted; for example, within a branch of the IF-THEN-ELSE statement.


2 Answers

It's not consistent across vendors - Oracle, MySQL, and DB2 support dual:

SELECT 'Hello world'   FROM DUAL 

...while SQL Server, PostgreSQL, and SQLite don't require the FROM DUAL:

SELECT 'Hello world' 

MySQL does support both ways.

like image 101
OMG Ponies Avatar answered Oct 02 '22 12:10

OMG Ponies


In Oracle:

SELECT 'Hello world' FROM dual 

Dual equivalent in SQL Server:

SELECT 'Hello world'  
like image 38
rebelliard Avatar answered Oct 02 '22 10:10

rebelliard