I'm creating a register web application for someone and I want to make student search to add a student to the activities register slightly more accurate.

At the moment my prepared statement is:

```
("SELECT * FROM students WHERE first_name LIKE :pattern OR last_name LIKE :pattern OR id LIKE :pattern ORDER BY last_name ASC");

```

And that works great. I returns a list of all students that match the search query. However after doing that query, for each row that returns I want to check if the students.id and $\_GET['activity'] do not appear in the participants table already.

$\_GET['activity'] is an ID from activities.id

**The final result I want is to display all students that are not already registered on that activity.**

Is this possible in one query? As if it is I'd rather do that then have to run a query on each returns result to see whether it should be displayed or not.

I have looked into INNER JOIN as I've used it before, but I don't feel that is what I need. My main issue is how to run that query to check if each result is in the participants table already.

Hopefully that will make sense as I'm finding it hard to work out how to word it in my head.

**My table structure:**

*students* - id PRIMARY KEY AI, first\_name (varchar255), last\_name (varchar255), dob (date)

*activities* - id PRIMARY KEY AI, title (varchar255), description (varchar255)

*participants* - id PRIMARY KEY AI, student\_id (INT), activity\_id (INT)