Martin
Martin

Reputation: 453

Nesting sql request

My sql is a bit rusty, but I do remember that it is possible to "nest" sql requests into each other. What I want to do is to load all invitations sent to a specific user, but only invitations to events that are not secret. My sql query looks like this:

SELECT * FROM invitations WHERE inviteeID = $uID

But what is missing here is that now it shows invitations to any event. I also want to test if the event.status is not 0 (secret). The event id is also in the table 'invitations'. All in all, it would look somehow similar to this:

SELECT * FROM invitations WHERE inviteeID = $uID AND events.eventID.status > 0

But thats not completely correct. How do I achieve this?

Upvotes: 0

Views: 31

Answers (1)

Saharsh Shah
Saharsh Shah

Reputation: 29051

You just have to JOIN both tables.

Try this:

SELECT * 
FROM invitations i 
INNER JOIN events e ON i.eventID = e.eventID 
WHERE inviteeID = $uID AND e.status > 0

Upvotes: 2

Related Questions