Home » SQL & PL/SQL » SQL & PL/SQL » Query (Oracle 11g)
Query [message #569832] Fri, 02 November 2012 07:10 Go to next message
UZUMAKI
Messages: 7
Registered: October 2012
Junior Member
Hello,

Once again you've been asking for help for a query. To a query I want to do is needed 3 tables, Table1, Table2 and Table3. In this Table 1 contains ID and NAME in this Table 2 contains ID, NAME, and ID_TABLE1 and Table 3 contains this ID, NAME, and ID_TABLE2.

The problem here is that I only get the ID Table1 and through it I have to go get all the information from the other tables. There is a possibility of doing it all in one query?
Re: Query [message #569833 is a reply to message #569832] Fri, 02 November 2012 07:14 Go to previous messageGo to next message
cookiemonster
Messages: 11202
Registered: September 2008
Location: Rainy Manchester
Senior Member
Looks simple enough, have you tried writing a query that joins the three tables?
If not, do so.
If you get stuck post what you tried.
Re: Query [message #569835 is a reply to message #569833] Fri, 02 November 2012 07:24 Go to previous messageGo to next message
UZUMAKI
Messages: 7
Registered: October 2012
Junior Member
What I did was split the query into two, since I need to get ID_TABLE2 get information from table 3. Then ask for help, I try to do everything and I am not in a can.

SELECT * FROM (SELECT TABLE1.ID, TABLE1.NAME, TABLE2.ID, TABLE2.NAME FROM TABLE1, TABLE2
WHERE TABLE1.ID = TABLE2.ID ORDER BY NAME) WHERE ID_TABLE1= $_GET[id]

SELECT * FROM (SELECT TABLE2.ID, TABLE2.NAME, TABLE3.NAME FROM TABLE2, TABLE3
WHERE TABLE2.ID = TABLE3.ID ORDER BY NAME) WHERE ID_TABLE2= $_GET[id]
Re: Query [message #569838 is a reply to message #569835] Fri, 02 November 2012 07:58 Go to previous message
cookiemonster
Messages: 11202
Registered: September 2008
Location: Rainy Manchester
Senior Member
Please read and follow How to use [code] tags and make your code easier to read?

The above selects are both invalid. You can't reference id_table1 in the outer query unless you select it in the inner query. Same for id_table2.
I would assume, based on the column names that table1.id joins to table2.id_table1 not table2.id as you have done.
I also don't see why there is any need for a sub-select here.

What's wrong with writing the query in the form:
SELECT <columns>
FROM table1, table2, table3
WHERE table1.column = table2.column
AND table2.column = table3.column
Previous Topic: Timestamp in mail generated from oracle is different
Next Topic: rownum > 5 and count(*)
Goto Forum:
  


Current Time: Wed Nov 26 18:32:27 CST 2014

Total time taken to generate the page: 0.13609 seconds