Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Reusing results

     
1:19 am on Feb 24, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 29, 2003
posts:94
votes: 0


Anyone help please?

Im stuck with this one, will try to explain.

I need to run a mysql query and put the results in some sort of variable where i can use them again.

example:

select * from table

result:

id = 1 colour = red
id = 2 colour = blue
id = 3 colour = green

then i have a script that does:

select * from table2

result:

colour id = 2

iwould like to say colour = blue without running the first query over over as its nearly 1000 times

It can probablt be done with a join but ive yet to understand joins fully

Its late im tired applogies if no one understands

Thanks

5:11 am on Feb 24, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 25, 2003
posts:94
votes: 0


From what I can tell, the following is what you need...

SELECT table2.color_id, table.color FROM table2 LEFT OUTER JOIN table ON table.id=table2.color_id;

7:46 pm on Feb 25, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


If you don't like joins then:

SELECT table2.color_id, table.color FROM table, table2 WHERE table.id=table2.color_id;

Start with simple WHERE, then you will understand JOINs
As I recall the difference is that join may be faster.
You can check that by running explain:

EXPLAIN SELECT table2.color_id, table.color FROM table, table2 WHERE table.id=table2.color_id;

EXPLAIN SELECT table2.color_id, table.color FROM table2 LEFT OUTER JOIN table ON table.id=table2.color_id;

Regards
Michal

3:08 am on Feb 26, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 29, 2003
posts: 94
votes: 0


Thanks to your answer i understand winglian's solution, all sorted with outer join

Many Thanks