Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 cross join problem

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-02-22 : 07:45:39
rgdharr writes "Sirs,

I am using sql server 2000.I have a employee master table. it contains the following fields (i'm just posting here only the reporting fields ok.)
emp_id (pk), emp_name

I have two child tables, say allowance_transaction, deduction_transaction.

fields in allowance_transaction : (again only reporting fields ok)

tranid(pk), emp_id(fk), allowance_name, allowance_amount

similarly, fields in deduction_transaction : (again only reporting fields ok)

tranid(pk), emp_id(fk), deduction_name, deduction_amount

i.e. one master and two child. I have 3 records in allowance_transaction and 2 records in deduction_transaction file.

when I make a query that retrieves emp_id,emp_name (from employee_master), allowance_name, allowance_amount(allowance_transaction), deduction_name, deduction_amount (from deduction_transaction), it gets cross joined and I am getting 6 records.

Pl. give me the correct query.

Advance thanks,

Kindly reply by email to my address please.

with regards,
rgdarr"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-02-22 : 07:57:09

You should give the proper condition in the Where clause


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-02-22 : 09:07:31
POST the SQL.....theory questions are harder to solve.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-02-22 : 09:08:48
you cannot join two transaction tables together in the same query. you need to summarize each one in a subquery by a common key first, and then join them together at the end.

in your case, sounds like you might want to GROUP each transaction subquery by EmpID and then join it all back together at the end based on that.

Does this help? Do you need an example?

- Jeff
Go to Top of Page
   

- Advertisement -