Home > Software design >  SQL Show one table with a foreing key from another table
SQL Show one table with a foreing key from another table

Time:12-05

I'm trying to display on SQL a table where the 1st table still the same but with the 2nd table the foreign key of this table will help to no show the foreign key on the fist table. Here's my tables,

Table Login

ID(foreign key), Username,Password,Level
1,test,test,Client
7,ClientU,ClientP,Client

Table Friends
ID_User,ID_Friends
7,1

My request is like when I put on a jsp page a table to no have the possibilities to add the same user again and over. Is it possible with an SQL command to display 0 lines if Login.ID = Friends.ID_User are equals that they don't show up. It will help on my JSP page.
Thanks in advance

CodePudding user response:

It may be possible to do like this : SELECT * FROM Login INNER JOIN Friends ON Login.id != Friends.id_user AND Login.id!=Friends.id_friend;

But I'm afraid if I add one more friends that others Users can't have this friend because it will not show up on the JSP table to add a friend because someone else will have this friend...

CodePudding user response:

I am not sure that I've understood your question properly. Could you please help me to understand it? I will describe how I understand your question in the next line:

I have a JSP page. A user can log into this page. After the user has logged in, the page should show the list of all other users, but it should not show the name of the user who is currently browsing this page.

Please read my description, and tell me if I understand correctly what's you're trying to accomplish.

  • Related