user2510952
user2510952

Reputation: 193

mysql multi table SELECT with conditions

I have been struggling to find a solution to the following situation. I have 4 tables

Table 1
product_id|product_name

Table 2
Review_id|listing_name|rating|content|product_id|user_id

Table3
user_id|user_name|

Table 4
user_id|rank|

product_id has the same values throughout Table 1 and Table 2 user_id has the same values throughout Table 2, 3, 4

I need help getting the following statement into one array

SELECT review_id, rating, content, user_name, rank FROM T2, T3, T4 WHERE              product_id=$pid and WHERE T3.user_id = T2.user_id 

My array should look like this:

$arr[review_id] = $row[review_id]
$arr[rating] = $row[rating]
$arr[content] = $row[content]
$arr[user_name] = $row[user_name]
$arr[rank] = $row[rank]

All help would be greatly appriciated

Upvotes: 0

Views: 58

Answers (1)

Hamza Kubba
Hamza Kubba

Reputation: 2269

SELECT T2.review_id, T2.rating, T2.content, T3.user_name, T4.tank
    FROM T2
    INNER JOIN T3
        ON T2.user_id = T3.user_id
    INNER JOIN T4
        ON T2.user_id = T4.user_id
    WHERE T2.product_id = $pid

Upvotes: 1

Related Questions