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.
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 .
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 .
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.
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.
In Oracle:
SELECT 'Hello world' FROM dual
Dual equivalent in SQL Server:
SELECT 'Hello world'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With