Jump to content

How to select data from 3 tables


golem

Recommended Posts

Hi ,

I try to get data from tehree tables.

any reason why this does not work?

 

(All the php variables are OK)

 

Thanks!

 

 

 

"

SELECT

users.name,

users.phone,

users.email,

 

user_books.bookTitle,

user_books.bookPrice,

 

user_hats.color,

user_hats.pattern

 

FROM users, user_books, user_hats

 

WHERE

      users.login = '$login'

AND users.password = '$pw'

AND user_books.user_id = '$userID'

AND user_hats.user_id = '$userID'

 

";

Link to comment
https://forums.phpfreaks.com/topic/48399-how-to-select-data-from-3-tables/
Share on other sites

Thanks but I can't get it to work.

its working with two tables:

 

"

SELECT

users.name,

users.phone,

users.email,

 

user_books.bookTitle,

user_books.bookPrice,

 

 

FROM users, user_books, user_hats

 

WHERE

users.login = '$login'

AND users.password = '$pw'

AND user_books.user_id = '$userID'

 

";

Better yet, use proper JOIN syntax:

 

SELECT 
users.name, 
users.phone, 
users.email, 

user_books.bookTitle, 
user_books.bookPrice, 

  
FROM users
INNER JOIN user_books ON (users.user_id = user_books.user_id) 
INNER JOIN user_hats ON (users.user_id = user_hats.user_id) 

WHERE 
   users.login = '$login'    
AND users.password = '$pw' 
AND user_books.user_id = '$userID'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.