skip to Main Content

Am having a MYSQL db and i want to select accounts thats connected in table users and table friends

this is my query

SELECT id(distinct FRIENDS.ID) FROM FRIENDS JOIN USERS ON FRIENDS.ACC IN (FRIENDS.ACC, FRIENDS.CONTO) 
    WHERE #USER FT11 IN (FRIENDS.ACC, FRIENDS.CONTO)

This is the error i get

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

TABLE USERS

ID USER_ACC NAME
1  FT11     JANE
2  FT22     FRED
3  FT33     KEN


TABLE FRIENDS

ID ACC  CONTO
1  FT11 FT33

ACC can be my account or CONTO can be my account
so i want to select or check these accounts am connected with on same column in FRIENDS table

2

Answers


  1. Probably this is what you want.

    SELECT u1.user_acct, u1.name, u2.user_acct, u2.name
    FROM Friends f
    JOIN Users u1 ON u1.user_acc = f.acc
    JOIN Users u2 ON u2.user_acc = f.conto
    
    Login or Signup to reply.
  2. I have added a code snippet:
    SELECT DISTINCT F.ID FROM FRIENDS F JOIN USERS U ON F.ACC = U.USER_ACC OR F.CONTO = U.USER_ACC
    WHERE U.USER_ACC = ‘FT11’;

    Try using this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search