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!

Retrieving data from different tables 2

Status
Not open for further replies.

nevets72

Programmer
Feb 6, 2002
22
US
Hi....I'm stuck.....I've got a table (I'll call it Table 'A') that has 4 records.....each record has one number associated with it. I've got another table (I'll call it Table 'B') that has 50 records, and again, each record is associated with one number. I need to multiply each individual number from Table 'A' by each individual number in Table 'B', thereby, my output would result in 200 values. How do I code this? Thanks!
 
What you are trying to create is a cartesian product. Normally it is what occurs when you have table joins. But in this case, just be sure. For each record in Tables A, you need to link that to each record in Table B?

Assume table A has fields ID, Name, Date
Table B has fields ID, Address, Phone

Select A.ID, A.Name, A.Date, B.ID as "ID B", B.Address, B.Phone from
A, B

When you don't specify a where clause like
A.ID = B.ID then it SQL Server will create for you a sitation like you are desiring.

Note*** I only aliaes the ID field in table B so that you would be able to tell which field was from which table when you get the out put....

 
SELECT TableA.X, TableB.Y, TableA.X * TableB.Y
FROM TableA, TableB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top