Inner Join 3 Tables in PHP

45 views Asked by At

I'm trying to develop a management system as a part of my thesis.

Question: What is wrong with the following query?

$query = "SELECT ab.bloodtype, dep.date_donated, dep.amount, sr.
        first_name, sr.last_name, loc.location_name
    FROM deposits AS dep 
    INNER JOIN donorstb AS sr ON dep.donor_id = sr.donorID 
    INNER JOIN available_blood AS ab ON dep.blood_id = ab.blood_id 
    INNER JOIN location AS loc ON dep.location_id = loc.location_id 
    ORDER BY donorID DESC;"

The desired output is something like the following:

Firstname | Lastname |    Date Donated    | Donated at | Bloodtype | Amount

Ron       | Flores   |  November 18,2017  |   Vigan    |    B+     | 2units
1

There are 1 answers

0
S. M. Imtiaz Hasan On

You need to share those tables. Whatever I just edit your code. Try It -

$query = "SELECT sr.first_name as Firstname, sr.last_name as Lastname, dep.date_donated as 'Date Donated', loc.location_name as 'Donated at', ab.bloodtype as Bloodtype, dep.amount as Amount
FROM deposits AS dep
INNER JOIN donorstb AS sr ON dep.donor_id = sr.donorID
INNER JOIN available_blood AS ab ON dep.blood_id = ab.blood_id
INNER JOIN location AS loc ON dep.location_id = loc.location_id
ORDER BY sr.donorID DESC;"