Select from multiple tables without a join?

后端 未结 8 1170
轻奢々
轻奢々 2020-12-05 01:53

What is the easiest way to select data from two tables and rather than join them, have them appear as separate rows. Both tables have similar or matching fields and I want t

8条回答
  •  囚心锁ツ
    2020-12-05 02:00

    Union will fetch data by row not column,So If your are like me who is looking for fetching column data from two different table with no relation and without join.
    In my case I am fetching state name and country name by id. Instead of writing two query you can do this way.

    select 
       (
       select s.state_name from state s where s.state_id=3
       ) statename,
       (
       select c.description from country c where c.id=5
       ) countryname
       from dual;   
    

    where dual is a dummy table with single column--anything just require table to view

提交回复
热议问题