Click here to Skip to main content
14,428,653 members
Rate this:
Please Sign up or sign in to 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
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 29-Aug-12 0:27am
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
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...
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

check logic of your query first.
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100