Click here to Skip to main content
15,898,953 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to show a record that have a duplicate 'slot.id_slot' value by syntax "slot.id_slot,count(*) 'Jumlah Bentrok '". But the record doesn't show when my syntax is :

SQL
SELECT  Jadwal.No_Jadwal, Kuliah.No,Doseen.Nama_Dosen , slot.id_slot,count(*) 'Jumlah Bentrok '
FROM Jadwal INNER JOIN Kuliah ON Jadwal.No = Kuliah.No INNER JOIN slot ON Jadwal.id_slot = slot.id_slot INNER JOIN  Doseen ON Kuliah.Id_Dosen = Doseen.Id_Dosen
group by Jadwal.No_Jadwal, Kuliah.No,Doseen.Nama_Dosen ,slot.id_slot having count(*) > 1


But, the record shows when my syntax becomes this:
SQL
SELECT [id_slot], count(*) 'Jumlah Bentrok'
  FROM [FKIP-UNILAK].[dbo].[Jadwal]
group by [id_slot] having count(*) > 1


What is the problem?
I have to show the record from my first syntax :(
Posted
Updated 17-May-11 9:47am
v2

If the record isn't showing, the problem has to be with your inner join statements. Basically, if all of your inner joins don't match, you won't get data back. If I were you, I'd analyse the data you think you should be getting back to see if you should be using inner joins or left/right joins.
 
Share this answer
 
First make a view for your join. Then perform the count operation. This will help you to divide and conquer your query.

Good luck.
 
Share this answer
 
I think it may be due to your underlying data. Since you have 3 inner joins, could you start with none of them, and incrementally add joins one at a time? Maybe you will be able to see which join is breaking it?
 
Share this answer
 

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