SQL查询后跟内连接

时间:2014-07-28 12:56:27

标签: php mysql sql inner-join

我需要在表上运行一个简单的查询来查找具有相应id的所有行。然后我想执行内连接。

 $applications = SELECT * FROM applications WHERE clubid = $_SESSION['id']

一旦我获得了符合此标准的所有行,我就会想要按照这一点执行某些操作。 $applications只是存储从上面的查询中找到的行。

SELECT *
FROM $applications
INNER JOIN productsapplied
ON $applications.ID = productsapplied.appid;

感谢您的帮助

3 个答案:

答案 0 :(得分:2)

将此全部作为一个查询执行:

SELECT *
FROM applications a INNER JOIN
     productsapplied pa
     ON a.ID = pa.appid
WHERE a.clubid = $_SESSION['id'];

答案 1 :(得分:0)

您可以将两个查询合并为

SELECT * FROM $applications
  INNER JOIN productsapplied
    ON $applications.ID = productsapplied.appid
  WHERE $applications.clubid = $_SESSION['id']

答案 2 :(得分:0)

我认为您可以使用“创建视图”

CREATE VIEW applications AS
 SELECT * FROM applications WHERE clubid = $_SESSION['id']

引用你

SELECT *
FROM applications
INNER JOIN productsapplied
ON applications.ID = productsapplied.appid;