0

I want to create mysql request to the server I want to retrieve users from the table that as I do not have in friends list.

Here's how I'm trying to learn but I do not receive please help me

SELECT
  t1.*, t2.*
FROM
  users as t1,
  friends as t2
WHERE
  t2.user_id='1'
  and t2.fr_id!=t1.id
ORDER BY RAND()
3
  • 2
    SHow us the tables sructure
    – GautamD31
    Commented Aug 22, 2013 at 11:13
  • Need to see the table structure. Commented Aug 22, 2013 at 11:16
  • @Стефан Симеонов or you learn SQL or you give us example data on sqlfriddle.. and ask your question better. I understand you want a result off poeple that arn't your friend already or do you want a list off users had have the same friend as you? Commented Aug 22, 2013 at 11:42

1 Answer 1

0

The query you want is something like:

SELECT t1.*, t2.*
FROM users t1 left outer join
     friends t2
     on t2.fr_id = t1.id and
        t2.user_id = '1'
WHERE t2.user_id is null
ORDER BY RAND();

I'm not sure what the t2.user_id = 1 is doing. It is not needed if you are looking through the entire friends list.

2
  • t2.user_id=1 (1 is my number for example) Commented Aug 22, 2013 at 11:17
  • this not show this what me need, showing my profile and my friends and other users i want to show only users who is no my friends. Commented Aug 22, 2013 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.