user3555501
user3555501

Reputation: 13

Mysql query to get data from 3 different tables for one userid

I have no idea how to get data from one query with php mysql.

here is my try

$sthpre = mysql_query("SELECT *
FROM users,
     file,
     friends
WHERE users.id='$other'
  AND file.user_id='$other'
  AND friends.user_id='$other'",$link) or die("Query  failed ");

i need to get for one user id i.e. 32 to get their binded values from other tables.

Upvotes: 0

Views: 143

Answers (1)

Saqueib
Saqueib

Reputation: 3520

You can use JOIN to get results from more than one table

SELECT * FROM users 
  JOIN file ON file.user_id = users.id 
  JOIN friends ON friends.user_id = file.user_id
WHERE users.id = $other;

Please let me know if it worked

Upvotes: 1

Related Questions