Shree Naath
Shree Naath

Reputation: 493

How to select query in oracle from 2 different tables?

I have created 2 tables as follows :

CREATE TABLE emp_bio(name VARCHAR2(15) NOT NULL ,id NUMBER, DOB DATE,PRIMARY KEY(id));

CREATE TABLE emp_sal(id NUMBER REFERENCES emp_bio(id), salary NUMBER,PRIMARY KEY(id));

Now, when I query as,

SELECT emp_sal.salary,emp_bio.name
FROM emp_sal right join emp_bio on emp_sal.id=emp_sal;

I get duplicate values in the output. Can anyone help me to remove that duplicate values !? Thank you.

Upvotes: 0

Views: 86

Answers (1)

Felix Pamittan
Felix Pamittan

Reputation: 31879

You want to do a JOIN on both tables using both tables' id columns, since they're the ones relating both tables:

SELECT
    eb.name,
    es.salary
FROM emp_bio AS eb
INNER JOIN emp_sal AS es
    ON es.id = eb.id

Upvotes: 1

Related Questions