I have a users table and friends table. The user with ID 1 has 4 friends (with IDs 2,3,4,13). I want to get names and surnames of users 2,3,4 and 13. I can to it with standard queries but it will slow down the process; querying for every friend. I didn't get how and what to use of left, joints, right joints, simple joints, ASs, ONs, …
Mysql – How to get a user’s friends’ names
MySQLquery
Related Question
- MySQL – Relational Schema Problem for Friendship and Messages with Big Data Manipulation
- Mysql – Retrieving most recent X rows for each given user from a table
- Mysql – Selecting/Matching cells that hold the same values as opposed to ID in MySQL/phpMyAdmin
- Mysql – Query returning all posts by friends and friends of friends
- Mysql – Different Indexes with different query duration
- Mysql – Can filtering be done more efficiently with/without sql joins
- Mysql – Get first and last record of a selection without using min() max()
- MySQL – Get Last Three Movements Per ID with LAG and GROUP BY
Best Answer
If you want to get the names of the friends for a user perhaps try something like so:
This should get a back a list of names in your user table (providing that is what you have named your friends in the user table) that are friends with userID 1
I'm guessing your friend table contains the foreign key IDs of the friends making up the partnership?