Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am joining two tables with INNER JOIN and I am getting duplicate entries.
I used DISTINCT but its not working.
Do we have some other keywords for the same?

Here is the query
SQL
Select Distinct(S1.RoomType),t.HotelName,S1.CIN From AgentPackagePrice t , BookDate S1 Where t.PackageNo=S1.PID  Or '2012-12-22 00:00:00.000'
 Between S1.CIN And S1.COUT And t.HotelName='ANCASA EXPRESS' and t.RoomType=S1.RoomType




[edit(zorgoz): tags changed]
Posted
Updated 28-Aug-12 23:27pm
v3
Comments
Zoltán Zörgő 29-Aug-12 5:22am    
Distinct IS working if you use it as you should. Post the DDL of these two tables and the query statement here. In some cases, GROUP BY can be also useful.
Member 8921522 29-Aug-12 5:23am    
Select Distinct(S1.RoomType),t.HotelName,S1.CIN From AgentPackagePrice t , BookDate S1 Where t.PackageNo=S1.PID Or '2012-12-22 00:00:00.000'
Between S1.CIN And S1.COUT And t.HotelName='ANCASA EXPRESS' and t.RoomType=S1.RoomType

Thats My Query

Read this:
http://blog.sqlauthority.com/2007/03/29/sql-server-difference-between-distinct-and-group-by-distinct-vs-group-by/
And try to remove the parenthesis from distinct. It is not a function.
Actually you do inner join, but you are using a WHERE without parenthesis. The OR can mislead you, be aware of the precedence!

This is the JOIN part, but I can not transcribe the rest, because I do not understand the logic. I don't know what your intention was
SQL
Select Distinct S1.RoomType,t.HotelName,S1.CIN 
From AgentPackagePrice t INNER JOIN BookDate S1 on t.PackageNo=S1.PID and t.RoomType=S1.RoomType
WHERE...
 
Share this answer
 
v2
check logic of your query first.
 
Share this answer
 
Comments
Zoltán Zörgő 29-Aug-12 5:24am    
This is not a solution, more a comment.
Member 8921522 29-Aug-12 5:33am    
Here I have 2 table first AgentPackagePrice And Second Bookdate

I have some value in first table & with some colum of 1st table or more column in 2nd table i want to get only those colun where date between given date or date can be null

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