Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Easy join but not sure how to do it

Author  Topic 

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-25 : 11:32:35
I have a table A and a table B

I want to display everything in table A and also display everything in table B

but, if 4 columns match, i want that row to display only the row in Table B, and if that row is a duplicate, I want it to display the one that's min(thatcolumn)

Does that make sense?

i tried

select *
from morganscleaner t full outer join
(select hotel, roomtype, checkindate, roomrate, executiontime
from morganscleaner
group by hotel, roomtype, checkindate, roomrate, executiontime) r

on t.hotel=r.hotel, t.roomtype = r.roomtype, t.checkindate = r.checkindate, t.executiontime = r.executiontime
order by hotel, roomtype, executiontime, checkindate

but its giving me a syntax error by the = error, I dont even think the above is correct anyway

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-25 : 11:35:52
Very few people understand waht you are trying to accomplish.
You have repeatedly been suggested to READ and FOLLOW the excellent guidelines found in this blog post
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-25 : 11:39:06
Otherwise replace your commas with AND

on t.hotel = r.hotel AND t.roomtype = r.roomtype AND t.checkindate = r.checkindate AND t.executiontime = r.executiontime
order by hotel, roomtype, executiontime, checkindate


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-25 : 11:39:28
quote:
Originally posted by Peso

Very few people understand waht you are trying to accomplish.
You have repeatedly been suggested to READ and FOLLOW the excellent guidelines found in this blog post
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx



E 12°55'05.25"
N 56°04'39.16"



sry, gimme a sec i'll redo it
Go to Top of Page
   

- Advertisement -