Oke my website works with Facebook Api, it will import all the friends (userId, name) of the user that will be logged in so my table structure is as following:
users: id, name
usersFriends: id, friendUserId, name
So when the users join the website, they will get all the friends imported, example data:
user: 237374734 (facebook user id), John brouwers (name of the user)
then it will import all the friends of John. for example:
userFriends: 237374734 (John user id), 2737373, Michael jackson
Now what I need is a query that will SEARCH (by name) through the friends, which is
no problem with just a join, but what I need is in the query I need to CHECK whether the user is on my website so lets take an example:
We logged in with the user John, and we are searching for michael so that would be
SELECT name FROM userFriends WHERE name LIKE %michael%
But what I need is NOT only return the name of the user, I also need a CHECK whether the user exists in the users table.
Sorry for the long story, hope that my question is clear. Thanks already!
Edit: So you need a query that search friends by Name and check whether the friend exists in the users table or not, As follows:
Here is the query that will search for the suer that his name
like "%Michael%"and check if he is a registered user or not:This will gives you:
Hope this will be helpful and if there is any problems don’t hesitate to ask.