WESTKINz
WESTKINz

Reputation: 257

SELECT in SQL QUERY - is it possible

Is it possible to SELECT name and address attribute from names table but at the same time I also want to combine description attribute from info table.

CREATE TABLE names(
ID CHAR(2) PRIMARY KEY
name VARCHAR2(20) NOT NULL
address VARCHAR2(40) NOT NULL
)
CREATE TABLE info (
ID CHAR(2) REFERENCES names
description VARCHAR2(80) NOT NULL
)

I Tried union method but failed

 SELECT name, address
FROM names
UNION
SELECT description
FROM info; 

is there any way to do it?

Upvotes: 0

Views: 86

Answers (4)

EKL
EKL

Reputation: 143

select n.name, n.address, i.description from names as n Left join info as i on n.id = i.id

Upvotes: 0

Anish Shah
Anish Shah

Reputation: 8169

SELECT name, address, description
FROM names JOIN info USING(id)

Upvotes: 2

juergen d
juergen d

Reputation: 204766

Yes, it is called a join

SELECT n.name, n.address, i.description
FROM names n
join info i on n.id = i.id

Upvotes: 0

Andomar
Andomar

Reputation: 238086

You could use a full outer join:

SELECT  n.name
,       n.address
,       i.description
FROM    names n
FULL OUTER JOIN
        info i
ON      i.id = n.id

Upvotes: 0

Related Questions