I’m not sure that a normal join will help me in the situation I have:
I have two tables as part of an app I’m building: one just lists a username in the first column and a friend's username in the second column. This table is strictly for keeping track of users and the users with whom they are friends.
The second table has 4 columns, username, last name, first name and password. This table is strictly for keeping track of registered users’ login and personal information.
I want to run a query on the first table to find all friends of the logged in user that contain a search term passed to the URL by javascript, which I have done:
SELECT friend FROM friends WHERE user='$user' AND friend
LIKE '%" . $term . "%'" //$user == $_SESSION['user']
This returns a list of usernames of the friends of the logged in user from the “friends” table that contain the search term $term.
Next, I want to run a query that returns the first name, last name and username of all users who match the first query (the friends of the logged in user) and whose first name or last name contain the same search term, $term, passed to the url by javascript. This query must be on the “user” table, since only it contains first and last names.
I’m just not sure how to join the tables and run the query in such a way as to get this information only for friends of the user.
1 Answer