0

I'm working through the book SQL Cookbook and there's an example where the author uses a query which is purely cosmetic (it's after the first union all statement):

select 
    ename as ename_and_dname, 
    deptno 
from emp 
where deptno = 10
union all
select 
    '----------', 
    null 
from t1
union all 
select 
    dname, 
    deptno 
from dept;

(The table t1 doesn't seem to have been defined yet in the text, but let's just assume the table exists and the query produces a single row.) It seems like it could be useful in SQL to have a kind of "empty table" that's a member of every database for performing such queries. In any case, what's the best way of doing this kind of thing?

1
  • 2
    For this specific case - don't do that - it adds formatting of output to data. The application should do such things.
    – jkavalik
    Commented Jul 23, 2015 at 5:53

1 Answer 1

1

You can use the DUAL table.

DUAL is purely for the convenience of people who require that all SELECT statements should have FROM and possibly other clauses. MySQL may ignore the clauses. MySQL does not require FROM DUAL if no tables are referenced. Quoting from MySQL doc-ref

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.