Davin Martyn

Davin Martyn

  • NA
  • 7.5k
  • 3m

Use top with join

May 13 2015 6:20 AM
Hi,
 
how to use top with join in sqlserver ? 

Answers (4)

0
Pankaj  Kumar Choudhary

Pankaj Kumar Choudhary

  • 71
  • 26.6k
  • 13.5m
May 13 2015 8:15 AM
Hello  @Davin you can see  this code

select  top(1) student.sname , Marks.marks from student
left outer join
Marks
on
student.sid=Marks.sid

here i use the top command with join  you can use any type of join like left,right ,inner  join as per your requirment....




0
Nanhe Siddique

Nanhe Siddique

  • 0
  • 2.5k
  • 367.2k
May 13 2015 6:47 AM
hi davin


Select top 1 a.*  from table1 a, table2 b where a.idcolumn=b.idcolumn order by the relavant_column

this is sample code to using top clause in sql



0
Gowtham Rajamanickam

Gowtham Rajamanickam

  • 75
  • 25.8k
  • 7.5m
May 13 2015 6:46 AM
http://stackoverflow.com/questions/2033699/top-1-with-a-left-join
0
Gowtham Rajamanickam

Gowtham Rajamanickam

  • 75
  • 25.8k
  • 7.5m
May 13 2015 6:45 AM
http://stackoverflow.com/questions/2043259/sql-server-how-to-join-to-first-row