Posted 29 October 2005 - 03:11 AM
I know there are ways to join information in 2 or more tables by using LEFT/RIGHT JOIN MySQL commands.
I've read the mysql.com documentation on it and it still confuses me. I don't understand why there are single letters placed before the table name ( m.foo, s.boo ) etc.
Does anyone have a tutorial or site that explains LEFT/RIGHT JOIN alittle better?
Posted 29 October 2005 - 01:08 PM
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM table1, table2 WHERE table1.id = '$id' AND table2.user = table1.id;
this can also be written like this (notice the letters and references are different:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM table1 a, table2 b WHERE a.id = '$id' AND b.user = a.id;
hope this helps
Posted 29 October 2005 - 01:20 PM
Just on more question. I noticed you didn't use a LEFT/RIGHT JOIN in there. What specifically would those be used for and would you mind creating a query with on of them in it and exlaining it to me like you did in your last post?
Thanks, i really appreciate it
Posted 29 October 2005 - 05:33 PM
SELECT * FROM table1 a, table2 b WHERE a.id = '$id' AND b.user = a.id;
the WHERE clause is specifying the join condition (b.user = a.id)
This is an alternative syntax and is equivalent to
SELECT * FROM table1 a INNER JOIN table2 b ON b.user = a.id WHERE a.id = '$id'
I always recommend the latter
1 ) it produces faster queries
2 ) it separates the relationship info from the search criteria and IMO shows more clearly what the query is doing.
Donations gratefully received
|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users