vinnie667
vinnie667

Reputation: 109

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. 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 $applicationsis just someway of storing the rows that were found from the above query.

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

Thanks for any help

Upvotes: 0

Views: 100

Answers (3)

Mikor
Mikor

Reputation: 27

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;

Upvotes: 0

Naveen Kumar Alone
Naveen Kumar Alone

Reputation: 7668

You could combine both querys as

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

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269543

Do this all as one query:

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

Upvotes: 2

Related Questions