Jump to content

Recommended Posts

Okay so first I will give you a rundown of the structure, then ask my question

 

Table 1: Friend status. Contains the friend id of one person then the friend id of who they have added as a friend.

 

Table 2: All the different friends

 

What I need to do is make a query that will select the people from table 2, that do not have an entry in table 1

 

So the table 1 structure may be

ID    userid    friendid

Where:

ID is just the general entry

Userid is the main user id

Friend id is the person they ahve added

 

 

Table 2 may have:

ID    Username    Password    hasfriended

 

 

It should only select those from table2 that have hasfriended as 0.

 

 

I am not too great at combining queries like this. Can anybody point me in the right direction?

Link to comment
https://forums.phpfreaks.com/topic/177356-multi-table-help/
Share on other sites

Okay it turns out I did not solve it.

 

First, I will show you my query:

SELECT 
   system.id
  ,system.username
      ,system.password
      ,system.followed
      ,follows.userid
      ,follows.systemid
  FROM system
INNER JOIN follows
WHERE system.followed=0 AND system.id != follows.systemid
  ORDER BY RAND() LIMIT 10

 

Basically, i need it to select a group of members from the system table, that have the "followed" field set to 0. Also, it has to check the follows table and makesure that the new id's it is selecting from the system table are not already listed in the follows table with the same userid

 

 

So here is my structure:

Table: System

id

username

password

followed

 

Table: Follows

id

userid

systemid

 

So basically, my query must select the amount from system. But the ones selected in system must have followed=0. It also must check the follows table to makesure that there is no insersion already that has the same userid and systemid as the new ones it is grabbing.

 

 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/177356-multi-table-help/#findComment-935156
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.