Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Query - Join 1

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hi,

I would need some help with a query. I'm trying to select the records from Table_1 which exists in Table_2.
So based on the data below (example) the records returned by the query would be:

Code:
ID|VALUE|NAME
133|T2|Type 2
141|T3|Type 3
175|T4|Type 4

DATA:

Code:
[i]TABLE_1[/i]
ID|VALUE|NAME
132|T1|Type 1
133|T2|Type 2
141|T3|Type 3
175|T4|Type 4

Code:
[i]TABLE_2[/i]
ID|NAME|TYPE_VALUE
8993|Best Buy|T2
9110|Price Chopper|T3
9330|Costco|T4
9666|Radio Shack|T2
9712|Wal-Mart|T4


Obviously, with this query I don't get the expected results.
Code:
SELECT TABLE_1.*, TABLE_2.*
FROM TABLE_1, TABLE_2
WHERE TABLE_1.VALUE = TABLE_2.TYPE_VALUE

Thanks in advance.
 
And this ?
Code:
SELECT DISTINCT A.ID, A.VALUE, A.NAME
FROM TABLE_1 AS A INNER JOIN TABLE_2 AS B ON A.VALUE = B.TYPE_VALUE

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

Thank you very much PHV. You get a big star for your help.

How come when I "Order By A.NAME", I get a "Not a SELECTed expression" ?

BTW. I'm on Oracle 9i.




 
I don't know Oracle's dialect, so just a guess:
SELECT DISTINCT A.ID, A.VALUE, A.NAME
FROM TABLE_1 AS A INNER JOIN TABLE_2 AS B ON A.VALUE = B.TYPE_VALUE
ORDER BY 3

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

It's working in Oracle. Thanks !
How come using the field name is not working ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top