in SQL Server is possible to execute a SELECT, without reference to a table; something like:
Select 1.2 +3, 'my dummy string'
As Oracle does not allow a SELECT without a FROM, I use the dual table for this type of operation; something like:
Select 1,2+3, 'my dummy string' FROM DUAL
There is a better way of doing this type of query? it is good practice to use the dual table?
To select values from SQL expressions, a FROM clause is not strictly required as the expression is not selected from that table anyway.
This depends on the database. In Oracle, IIRC, the from is required. But Oracle has a table DUAL which always returns one row for cases where all the work is being done in the SELECT clause.
Using SELECT without a WHERE clause is useful for browsing data from tables. In a WHERE clause, you can specify a search condition (logical expression) that has one or more conditions. When the condition (logical expression) evaluates to true the WHERE clause filter unwanted rows from the result.
If you use the asterisk (*) in the application code and assume that the table has a fixed set of columns, the application may either not process the additional columns or access the removed columns.
No, in Oracle
there is no SELECT
without FROM
.
Using the dual
table is a good practice.
dual
is an in-memory table. If you don't select DUMMY
from it, it uses a special access path (FAST DUAL
) which requires no I/O
.
Once upon a time, dual
had two records (hence the name) and was intended to serve as a dummy recordset to duplicate records being joined with.
Now it has but one record, but you can still generate an arbitrary number of rows with it:
SELECT level FROM dual CONNECT BY level <= 100
MySQL
also supports dual
(as well as the fromless syntax).
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