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)
 SQL Query showing duplicates

Author  Topic 

maruthi_p
Starting Member

8 Posts

Posted - 2009-12-04 : 00:16:56
Hi,
I'm having 2 tables namely handset_details and offers, handset_id is the primary key in handset_details table and foreign key in offers table,I now need to pick handsets which are present in both handset_details and offers table which are mapped to an offer_id primary key in offers table.
i've written my query like this, but when it gets executed its showing DUPLICATES like printing the same record TWICE.
can anyone please help me out, here is my query.

 set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[usp_get_phones_by_make_ID]
(@manufacturar_id int)
AS
select
handset_details.handset_id,
offer_details.offer_id,
offer_details.tariff_detail_id,
handset_details.handset_image_small,
handset_details.handset_dec,
handset_details.handset_weight_grams,
handset_details.handset_length_cm,
handset_details.handset_width_cm,
handset_details.handset_breadth_cm,
lkp_hardware_manufacturars.manufacturar_desc

FROM offer_details, handset_details, lkp_hardware_manufacturars

WHERE offer_details.handset_id = handset_details.handset_id AND lkp_hardware_manufacturars.manufacturar_id = @manufacturar_id AND
handset_details.manufacturar_id = lkp_hardware_manufacturars.manufacturar_id




Awaiting your help, Many Thanks..


vikky
Yak Posting Veteran

54 Posts

Posted - 2009-12-04 : 00:44:47
hi,


use DISTINCT keyword then also u get the duplicates post with sample data.

Thanks,
vikky.
Go to Top of Page

cvraghu
Posting Yak Master

187 Posts

Posted - 2009-12-04 : 00:47:26
Are you sure each handset has only one offer? Post sample data in tables and output to help you out.
Go to Top of Page
   

- Advertisement -