Results 1 to 4 of 4
Mar 3, 2003, 13:35 #1
MySQL SELECT with Multiple Tables
i want to select some rows from my database from multiple tables
i use this code:
$sql = mysql_query("SELECT * FROM $mulchtable, $snipetable, $conctable, $rjumptable WHERE winner = '$name' ORDER BY date DESC LIMIT 5");
( because i havent tested it, it may be ASC becasue i get confused sometimes ) or will it only select 5 from 1 table ?
If it selects from just the one table is there an easier way of selecting
from multiple tables ?
Mar 3, 2003, 14:32 #2
- Join Date
- Jun 2000
- Sydney, Australia
- 0 Post(s)
- 0 Thread(s)
You really need to read up on how joins work. I don't think you will be happy with the results of that query. The idea of a relational database is that there are relationships between the tables ("relations") in the table.
You probably need to specify on which keys to join the tables together.
FROM table1, table2, table3
WHERE table1.value = table2.foreignkey
AND table2.value = table3.foreignkey
Get the idea?
Mar 3, 2003, 14:49 #3
im quite flouent in PHP but only know some VV basic MySQL
i dont get the idea of a foreignkeys ?
what are they ?
Mar 3, 2003, 19:18 #4
- Join Date
- Jul 2002
- Toronto, Canada
- 49 Post(s)
- 1 Thread(s)
foreign keys are the values that relate rows in different tables
here's a very simple example
consider categories -- catid is the primary key
now here's another table -- thingid is the primary key, and catid is the foreign key
thingid thingdesc catid
104 quartz 14
105 tomato 13
106 cat 12
107 cow 12
108 granite 14
109 naked molerat 12
110 copper 14
foreign keys reference primary keys
in most databases (not mysql), you cannot enter a row with a value in the foreign key that does not exist in the primary key
you could not, for example, enter
111 sandwich 15
becaase 15 isn't in the categories table
you don't have to check it -- the database does it for you (again, not mysql)
if you want more, check some of the links on my site --