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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Joining unrelated tables

Author  Topic 

rlull
Starting Member

39 Posts

Posted - 2006-09-21 : 13:22:39
Is there a way to join tables that don't have any relationship? For example (this doesn't actually work correctly but something along these lines)

SELECT Schedule.*, Calendar.*
FROM Schedule, Calendar
WHERE NOT EXISTS(SELECT * FROM Schedule WHERE Schedule.GameDate = Calendar.EventDate)

I am trying to return a single recordset where if a record from Schedule has the same date as a record from Calendar, the Schedule record is selected not the Calendar one. Both tables have different columns and I am unable to use a UNION. The only thing the tables have in common is the date field.

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2006-09-21 : 13:27:50
show us sample input data from both the schedule and calendar tables and a matching result set?
We're guessing otherwise.
Go to Top of Page

rlull
Starting Member

39 Posts

Posted - 2006-09-21 : 13:41:13
Calendar table includes these fields which are self describing:
Calendar.EventDate, Calendar.EventName, Calendar.EventTime, Calendar.Description, Calendar.EventLocation

Schedule table:
Schedule.GameDate, Schedule.Time, Schedule.Season, Schedule.Opponent, Schedule.Home_Away, Schedule.Location

I want to return all the above fields for each row. In the event that both tables return a row with the same date (Calendar.EventDate = Schedule.GameDate), I want to show only the information from the Schedule table.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-21 : 16:28:19
You already got an answer here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=72362

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2006-09-21 : 23:00:09
You can join anything to anything else. Remember it's just sets - nothing anywhere says there must be a relationship enforced or even that the relationship has to be based upon equality. It's just data sets - if it makes sense to your data and what you are trying to achieve then just do it! (It's the last bit that trips most people up).
Go to Top of Page
   

- Advertisement -