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)
 help on the query pls

Author  Topic 

Sarakumar
Posting Yak Master

108 Posts

Posted - 2009-03-18 : 00:25:09
hai,
i have custmer table,
in which i have custid and person info abt the customer .
anothere tble with itemdtl
in which i have ,custid and itempurchased..
it is like this
tblcust
custid
custname
custaddr

tblitemdtl
custid
itemno
itemname

it will look like this in dtl table


c1 1 laptop
c1 2 comp
c1 3 headph

i want to get the custid group by itemname..but i want to get the distinct of custid,how can i do that.
help pls

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-18 : 00:38:10
select distinct c.custid, c.custname,i.itemno,i.itemname from
tblcust c
inner join tblitemdtl i on c.custid = i.custid
Go to Top of Page

Sarakumar
Posting Yak Master

108 Posts

Posted - 2009-03-18 : 00:46:21
quote:
Originally posted by bklr

select distinct c.custid, c.custname,i.itemno,i.itemname from
tblcust c
inner join tblitemdtl i on c.custid = i.custid



For the above criteria, i need to get only one row as output..
the above query will give all the three rows.That's y im confused
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-18 : 00:50:02
u want the output as
c1 1 laptop

then use top 1
Go to Top of Page
   

- Advertisement -