tags:

views:

44

answers:

2

Hello, 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.

A: 

you need join. something like

SELECT custname, location FROM a JOIN b ON a.custid = b.custid WHERE age = [age];
second
+3  A: 

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 = #
Brett
For performance reasons, it's generally preferable not to put a filtering clause (a.Age = #) into a join condition, as in the second option. Has to process more rows in A during the join.
orbfish
@orbfish - good to know, thanks for the tip!
Brett