[PHP-DB] JOIN statement not producing expected output
Okay, now this is my first try on fetching data from two tables, and frankly I'm starting to pull my hair out ;) All I want is to fetch some data from two seperate tables in my database. So far I have tried different approches, and below is what I think should work, but doesn't :( SELECT * FROM table1,table2 This I pasted into phpmyadmin, and it outputted two rows from table2 with ekstra columns at the tail of each row. These ekstra columns was just the same output from table2. Now I have searched the web, but have not found a simple solution for my problem. Any ideas? If you need more info, please let me know :) -Lasse -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] JOIN statement not producing expected output
Okay, now this is my first try on fetching data from two tables, and frankly I'm starting to pull my hair out ;) All I want is to fetch some data from two seperate tables in my database. So far I have tried different approches, and below is what I think should work, but doesn't :( SELECT * FROM table1,table2 This I pasted into phpmyadmin, and it outputted two rows from table2 with ekstra columns at the tail of each row. These ekstra columns was just the same output from table2. Now I have searched the web, but have not found a simple solution for my problem. Any ideas? If you need more info, please let me know :) -Lasse -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] JOIN statement not producing expected output
Well, the first question is what's the expected output? If you're trying to get, say, title from table1 and rating from table2 and identify the books in table1 by the unique field id and in table2 by the field book_id, then this is what you should have to end up with: SELECT t1.title, t2.rating FROM table1 as t1, table2 as t2 where t1.id=t2.book_id; This is obviously a simple example, and depending on what your problem is, it may not help. But it's a good start for simple generic JOIN's. HTH Bogdan admin wrote: Okay, now this is my first try on fetching data from two tables, and frankly I'm starting to pull my hair out ;) All I want is to fetch some data from two seperate tables in my database. So far I have tried different approches, and below is what I think should work, but doesn't :( SELECT * FROM table1,table2 This I pasted into phpmyadmin, and it outputted two rows from table2 with ekstra columns at the tail of each row. These ekstra columns was just the same output from table2. Now I have searched the web, but have not found a simple solution for my problem. Any ideas? If you need more info, please let me know :) -Lasse -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] JOIN statement not producing expected output
If you're looking to do cross-table joins, I'd advise a good book/class on basic SQL or you're going to get in over your head very very quickly. SELECT * FROM table1,table2; This WILL run, but there's no where clause. Therefore it will return all of table1 matched against all of table 2. SELECT * FROM table1,table2 WHERE table1.col1 = table2.col2; will limit your result set to the match of the two tables (and is an implicit INNER JOIN call.) The SQL language is (mostly) database independant. Here's a link to the mySQL website which'll give some basic info on SELECTs. http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#SELECT 'Luck -Szii - Original Message - From: admin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, May 20, 2002 5:48 PM Subject: [PHP-DB] JOIN statement not producing expected output Okay, now this is my first try on fetching data from two tables, and frankly I'm starting to pull my hair out ;) All I want is to fetch some data from two seperate tables in my database. So far I have tried different approches, and below is what I think should work, but doesn't :( SELECT * FROM table1,table2 This I pasted into phpmyadmin, and it outputted two rows from table2 with ekstra columns at the tail of each row. These ekstra columns was just the same output from table2. Now I have searched the web, but have not found a simple solution for my problem. Any ideas? If you need more info, please let me know :) -Lasse -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php