[thelist] [mysql] join
Tab Alleman
Tab.Alleman at MetroGuide.com
Wed Jan 28 13:26:19 CST 2004
Joshua Olson wrote:
> ----- Original Message -----
>> SELECT some_other_stuff, t1.name AS name1, t2.name AS name2 FROM
>> table_one INNER JOIN table_two t1
>> ON t1.id = table_one.id_one
>> OR t2.id = table_one.id_two
> In the query you suggested above,
> the t2 table is never referenced...
Doh, I copied and pasted and cut and did not scrutinize. My bad (must
remember to think more safely)...but I thought the original problem
would have been solved by something like this:
SELECT some_other_stuff, t2.[name] FROM
table_one INNER JOIN table_two t2
ON t2.id = table_one.id_one
OR t2.id = table_one.id_two
> So, we will not be
> able to return in the result a single row that contains information
> from one record of table_one and two separate records from table_two.
Which makes perfect sense; I just don't remember that being part of the
original poster's request. Her 3-query solution wouldn't have produced
one row with both names from table_two, it would have produced a
separate row for each name...wouldn't it?
-----------------
$sql_one = "select id_one, id_two, some_other_stuff from table_one where
x";
query
fetch_rows
$sql_two = "select name from table_two where id = id_one";
$sql_three = "select name from table_two where id = id_two";
-----------------
Unless she's doing something in the middleware that I don't know
about....her original post didn't include desired sample output. Also
her 3-query solution would have produced duplicate records in cases
where both ID's matched. My OR-solution probably wouldn't do that, huh?
That may or may not be a Bad Thing.
> (where's rudy when ya need him?) :-)
He seems to be involved in some kind of networking project. Er,
networking IT professionals that is--not computers.
More information about the thelist
mailing list