vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| SELECT product_name, customer.name, date_of_sale FROM `sales` , product, customer WHERE product.product_id = sales.product_id and customer.customer_id = sales.customer_id LIMIT 0, 30 The above SQL command links three tables and display the required result. The tables are linked by their ID fields. <http://www.plus2net.com/sql_tutorial/sql_linking_table.php> how is this different/better than a many-to-many, such as <http://www.plus2net.com/sql_tutorial/sql_inner_join.php>? Isn't that a better way of doing the same thing? Or, not? thanks, Thufir |
| |||
| Thufir wrote: > SELECT product_name, customer.name, date_of_sale > FROM `sales` , product, customer > WHERE product.product_id = sales.product_id > and customer.customer_id = sales.customer_id LIMIT 0, 30 > > The above SQL command links three tables and display the required > result. The tables are linked by their ID fields. > > <http://www.plus2net.com/sql_tutorial/sql_linking_table.php> > > > how is this different/better than a many-to-many, such as > <http://www.plus2net.com/sql_tutorial/sql_inner_join.php>? Isn't that > a better way of doing the same thing? Or, not? > > > > thanks, > > Thufir > Maybe i'm crazy and it's just late but i'm pretty sure what you have there IS an inner join. Inner join is the default join type if you don't explicitly specify the join type. If you do specify the join type you'd have to use ON or USING. |
| ||||
| Hi, Thufir wrote: > SELECT product_name, customer.name, date_of_sale > FROM `sales` , product, customer > WHERE product.product_id = sales.product_id > and customer.customer_id = sales.customer_id LIMIT 0, 30 > > The above SQL command links three tables and display the required > result. The tables are linked by their ID fields. > > <http://www.plus2net.com/sql_tutorial/sql_linking_table.php> > > > how is this different/better than a many-to-many, such as > <http://www.plus2net.com/sql_tutorial/sql_inner_join.php>? Isn't that > a better way of doing the same thing? Or, not? I agree with the other respondent: they are the same thing. The comma-join syntax in your first example is an "old-style" join, which used to be the only way to join tables. The join using the JOIN keyword is equivalent, and I call it "ANSI-style" or "new-style" or just "the right way." I think whoever wrote the tutorial is using the words "linking table" a little carelessly. Many RDBMS products have a notion of "linked tables" that is *totally* different -- it has to do with accessing a table on one server from another server. While it's true a JOIN, comma-style or not, does "link" data in one table to another table, it is NOT a "SQL LINKING TABLE command" as implied in the tutorial. It is a JOIN, and there is no such command as far as I know. Baron |