Forum Moderators: open

Message Too Old, No Replies

2 Tables / Same Fields

not sure why this join isn't resolving properly

         

Murdoch

5:02 pm on Jul 14, 2008 (gmt 0)

10+ Year Member



I've got a MySQL query that I'm not sure why it isn't working. I've got two tables with the same fields (the entries are based on gender) and I thought that this query would work properly but I guess not:

SELECT t1.*, t2.* FROM t1, t2 WHERE (t1.cat = 'value' AND t1.status = 'active') OR (t2.cat = 'value' AND t2.status = 'active')

Since the fields are the same between the tables, I resolve the WHILE loop with a mysql_fetch_array that just calls for the fields that should be coming up regardless of table name. I'm a little short on knowledge when it comes to joins I'm guessing there's a better way to do it than this because right now whichever table is called first isn't even showing up in the results.

Thanks

edit - syntax mistake

[edited by: Murdoch at 5:03 pm (utc) on July 14, 2008]

physics

11:04 pm on Jul 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What exactly are you trying to get with your query?

From reading your post a few times it sounds like two separate select statements, one for each table, might work fine...

maximillianos

11:19 pm on Jul 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to "join" the keys from each table. But it does not sound like you even want to do a join.

Perhaps you are meaning to do a "union"?


(SELECT t1.* FROM t1 WHERE t1.cat = 'value' AND t1.status = 'active')
UNION
(SELECT t2.* FROM t2 WHERE t2.cat = 'value' AND t2.status = 'active')

Murdoch

2:05 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



Max, that is definitely what I was looking for. I was unaware you could even do mutiple SELECT statements.

Thanks

maximillianos

9:02 pm on Jul 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool. Let me know if you need anything else!