在PHP中内部加入3个表

时间:2017-11-19 05:09:20

标签: php sql

我试图将管理系统作为我论文的一部分。

问题:以下查询有什么问题?

$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;"

所需的输出如下所示:

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

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

1 个答案:

答案 0 :(得分:0)

您需要共享这些表格。无论我只是编辑你的代码。试一试 -

$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;"