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 2005 Forums
 Transact-SQL (2005)
 Using a query as an inner join

Author  Topic 

mrm23
Posting Yak Master

198 Posts

Posted - 2009-01-06 : 05:10:33
Hi,

I have used a subquery in the inner join in one of my SPs.
The subquery returns more than 1 values.
so i am getting duplicate records in my outer query.
How can we avoid this?

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-06 : 05:37:42
use distinct keyword in ur subquery
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-06 : 05:41:39
Also Use Group By clause in the query
Go to Top of Page

mrm23
Posting Yak Master

198 Posts

Posted - 2009-01-06 : 05:58:56
Hi,

i have used distinct. the problem is the query is dependent on a date range. if you check for a single date it works fine, but for two different dates it is giving duplicates

Like, the query in the join returns two rows and with the outer query it is giving 4 rows.
i want to remove the two duplicate records. distinct is not working.....
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-01-06 : 06:01:12
show us the query with sample data, output you are getting and desired output.
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-06 : 06:13:47
Use Distinct to avoid duplicates else
Post your query ,,,,
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 08:50:59
quote:
Originally posted by mrm23

Hi,

i have used distinct. the problem is the query is dependent on a date range. if you check for a single date it works fine, but for two different dates it is giving duplicates

Like, the query in the join returns two rows and with the outer query it is giving 4 rows.
i want to remove the two duplicate records. distinct is not working.....


that may be because date values are different. please remember that distinct looks over entire row and gives only distinct combination of all the values, so there can be chance that you get same value for other fields with just date differing. In any case, please post some sample data as requested and show us what values you need to retrive
Go to Top of Page
   

- Advertisement -