简体   繁体   English

SQL查询后跟内部联接

[英]SQL query followed by inner join

I need to run a simple query on a table to find all the rows with a corresponding id. 我需要在表上运行一个简单的查询,以查找具有相应ID的所有行。 I then want to perform an inner join. 然后,我想执行内部联接。

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

Once I have got all of the rows which meet this criteria, I then want to perform something along the lines of this. 一旦获得了所有符合此条件的行,我便想按照此原则执行一些操作。 The $applications is just someway of storing the rows that were found from the above query. $applications仅用于存储从上述查询中找到的行。

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

Thanks for any help 谢谢你的帮助

Do this all as one query: 作为一个查询来完成所有操作:

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

You could combine both querys as 您可以将两个查询合并为

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

I think you can use Create View 我认为您可以使用创建视图

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

And quoting you 并引用你

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM