Jimmy
Jimmy

Reputation: 2106

need help on sql query

am a newbie to Oracle/PL SQL.I've 2 tables A and B. A has a column CustId,Age,Location and Date. Table B has 2 columns CustId,CustName.

What would be the sql query to show show CustName and Location for a given age?

Thanks.

Upvotes: 0

Views: 70

Answers (2)

Brett
Brett

Reputation: 4061

your question "What would be the sql query to show show CustName and Location for a given age?" helps define your query pretty well:

SELECT CustName, Location
FROM TableA a
INNER JOIN TableB b
ON b.CustId = a.CustId

WHERE a.Age = #

All we need to do on top of that select for your specific fields is make sure to join the two tables on their common column (CustID).

Another option would be to avoid the WHERE statement:

SELECT CustName, Location
FROM TableB b
INNER JOIN TableA a
ON a.CustID = b.CustID
AND a.Age = #

Upvotes: 3

second
second

Reputation: 28655

you need join. something like

SELECT custname, location FROM a JOIN b ON a.custid = b.custid WHERE age = [age];

Upvotes: 0

Related Questions