![]() |
|
|
#1 |
|
Senior Member
Join Date: Jul 2004
Posts: 167
|
What is the "right" join for the job?
I want to match a field to 10 tables. It appears in some tables once, in other tables twice, in other tables not at all. I can't seem to find the right join for the job. I either get too many rows, not enough rows or incorrect rows.
Can someone help please? Table 1 ============= t1id | userid | flag | score -------------------------- 1 | 1003 | red | 10 2 | 1003 | red | 5 3 | 1005 | blue | 15 Table 2 ============= t2id | userid | flag | score -------------------------- 1 | 1012 | yellow | 7 2 | 1002 | green | 4 3 | 1001 | red | 1 Table 3 ============= t1id | userid | flag | score -------------------------- 1 | 1012 | orange | 10 2 | 1022 | blue | 10 3 | 1023 | blue | 10 ================================================== ======== I want to join these three tables on the value of red and get no data for table 3 and two rows for table 1. So something like this should be the result: ---------------------- Result ============= userid | flag | score -------------------------- 1003 | red | 10 1003 | red | 5 1001 | red | 1 ================================================== ======== |
|
|
|
|
|
#2 |
|
Member
Join Date: Feb 2005
Location: ANtwerp - Belgium
Posts: 34
|
Re: What is the "right" join for the job?
This seems to me like you need a union.
You should try this statement : select * from T1 where flag = "red" UNION select * from T2 where flag = "red" UNION select * from T3 where flag = "red" |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Cross dependency found in OUTER JOIN SQL | rjmthezonenet | SQL syntax | 0 | 12-05-2004 04:41 PM |
| help with join | shaunperry | SQL syntax | 0 | 10-07-2004 06:22 AM |