Question

  Asked: Nov 27 2007   2:58 AM GMT
  Asked by: TeamJR3


Showing all records


SELECT statement, JOIN

DATA SET:

Table1
XID YID WRKDATE
--- --- -------
1 NOR 2007-01
2 SOU 2007-03

Table2
XID ZID QTY
--- --- ---
1 PEN 10
1 PAP 20
2 PAP 5
1 PEN 10
2 PAP 5

Result
XID YID WRKDATE ZID QTY
--- --- ------- --- ---
1 NOR 2007-01 PAP 20
1 NOR 2007-01 PEN 10
1 NOR 2007-01 PEN 10
2 SOU 2007-03 PAP 5
2 SOU 2007-03 PAP 5

Not This Result
XID YID WRKDATE ZID QTY
--- --- ------- --- ---
1 NOR 2007-01 PAP 20
1 NOR 2007-01 PEN 10
2 SOU 2007-03 PAP 5

I have tried the following query but kept getting the un-desired result.
Select * from table1, table2 where table1.XID=table2.XID

I have tried joins and still get the un-desired result.

Any hints will be appreciated.

Thanks.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+2
Click to Vote:
  •   2
  •  0



Hi,

The query you posted:

Select * from table1, table2 where table1.XID=table2.XID

should produce the five-row result set (with duplicates) that you want. It does when I run it in Oracle 10. To get the three-line results, I have to say "SELECT DISTINCT ...".

The opposite of "SELECT DISTINCT" is "SELECT ALL". I've never used it before, because it's always been the default, but it could solve your problem. Try:

Select ALL * from table1, table2 where table1.XID=table2.XID
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Database.

Looking for relevant Database Whitepapers? Visit the SearchOracle.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

TeamJR3  |   Nov 27 2007  5:09PM GMT

Thanks Frank.
Actually, by you confirming that this does work, I was able to see the problem. Unfortunately, I am only an end-user and do not have the tools to create test tables. On my question, I have used ficticious column names.
But, what the problem was when I did the query ..
“select table.*, table2.ZID, table2.QTY from table1, table2 where table1.XID=table2.XID”, it yielded the un-desired result.
However, there is also a unique identifier in table2 with the column name of LID. When I added that to the query, due to the distinct value in LID, it gave me the result that I needed.
Thanks for your help.