Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am firing single query on table with joins on other 3 tables , I want only one row in result,
in 3 tables one unique id is uead ,but in last table no of entries for that id , so i get multiple records , i only want first record ,?

There is only one id is common in last table and other table

Thanx in advance ,..
Posted
Comments
OriginalGriff 7-Dec-13 4:41am    
What query are you using at the moment?
[no name] 7-Dec-13 5:01am    
select a.col1 as 'bug id',

a.col2 as 'Description',
a.col3 as 'Project',
a.col4 as 'Oraganization',
b.col2 as 'category',
a.col5 as 'Reported On',
a.col6 as 'Source No',
a.col7 as 'Reference Doc No',
c.col2 as comment

from tablefirst a
left join tablesecond b on a.col7=b.col1
join thirdtable c on a.col1=c.col1 and c.bp_type='comment'

where a.col1 > 6000 ;

1 solution

Use top 1, if you are using sqlserver.If you are using oracle where rownum=1
eg SQL Server: select top 1 * from (your select query) alias;
eg Oracle: select * from (your select query) alias where alias.rownum=1;
 
Share this answer
 
v2
Comments
[no name] 7-Dec-13 4:50am    
top 1 will remove all remaining records ..i want one record for id =1 ,for id=2 ,id =3
s#@!k 7-Dec-13 5:03am    
not clear do some more explanation total how many records you want from the result set and in which way.
[no name] 7-Dec-13 5:05am    
sir ,there are multiple records for single id , i want only one record for one id
madhuri@mumbai 7-Dec-13 5:50am    
Used Distinct keyword.
Apply Distinct on ID field ,you will get distinct record for each id.
s#@!k 7-Dec-13 6:44am    
do group by you will all distinct record set.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900