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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Relational Database Question

Status
Not open for further replies.

nasium

Programmer
Jan 15, 2003
3
US
So I have a slight problem that I would really like to figure out.
Im kinda new to SQL so excuse the simplicity of my question.
I have 2 tables containing products and the other, dates relevent to the products.

TableOne:
-ID
-productID
-Product

TableTwo:
-ID
-productID
-dateOne
-dateTwo
-dateThree

I extract the data using a join WHERE TableOne.productID = TableTwo.productID AND displaying only the dates where its greater then current date()

The problem lies here.
Each product can have mulitple TableTwo.productID data\rows relating to one TableOne.productID.
I want to retrieve each TableOne.productID and all the data it relates to in TableTwo in one recordset.

This would be my ideal recordset
--------------------------------------------------------------------------------------------------------------------------------------
| TableOne.productID(1) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo|
--------------------------------------------------------------------------------------------------------------------------------------
| TableOne.productID(2) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo | TableTwo.dateOne | null | TableTwo.dateTwo|
--------------------------------------------------------------------------------------------------------------------------------------
| TableOne.productID(3) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo | null | TableTwo.dateTwo | TableTwo.dateTwo|

My current recordset contains this data
------------------------------------------------------------------------------
| TableOne.productID(1) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo |
------------------------------------------------------------------------------
| TableOne.productID(1) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo |
------------------------------------------------------------------------------
| TableOne.productID(1) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo |
------------------------------------------------------------------------------
| TableOne.productID(2) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo |
------------------------------------------------------------------------------
| TableOne.productID(2) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo |
------------------------------------------------------------------------------
| TableOne.productID(2) | TableTwo.dateOne | TableTwo.dateTwo | TableTwo.dateTwo |

So in plain english, I want each product returned containing all the dates that match each product.
Any tips or pointers would be great. Thanks for the help.

Jorge
 
What you are currently getting is pretty much the way it works in SQL. However, if you are using Oracle and SQLPlus, you can set a BREAK on productID with NODUP
to suppress the repeating productID. Other RDBMS utilities probably have similar capabilities.

If, on the other hand, you want the productID with a large parade of dates, you will have to go over to some procedural approach. In Oracle, this would probably involve PL/SQL and explicit cursors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top