Jump to content

[SOLVED] Query Issue (crossing tables)


Canman2005

Recommended Posts

Hi all

 

Wondering if anyone can help.

 

Basically I have a `members` table which looks like

 

`MEMBERS` - TABLE

ID      NAME     MYID
1       John     11
2       Dave     2
3       Emma     11
4       Sarah    11
5       Steve    8

 

What I do then is run a QUERY on this table to get all the members which belong to me (I am ID number 11), this would be done with a QUERY like

 

SELECT * FROM `members` WHERE `myid` = 11

 

that would get the following rows back from the `members` table

 

`MEMBERS` - TABLE

ID      NAME     MYID
1       John     11
3       Emma     11
4       Sarah    11

 

This shows that ID numbers 1 / 3 / 4 belong to me as my member ID is stored on thier row.

 

What I want to do is run another QUERY on a table called `posts` which gets all the rows which belong to those members returned from the `members` table.

 

The posts table looks like

 

`POSTS` - TABLE

ID      TITLE     MEMBERID
1       Hello     2
2       Holiday   4
3       Travel    9
4       Boats     4
5       Planes    6

 

So when I run the QUERY i'm trying to figure out, it would basically return the following rows

 

`POSTS` - TABLE

ID      TITLE     MEMBERID
2       Holiday   4
3       Travel    3
4       Boats     4

 

because the `member` id's that belong to me (1 / 3 / 4) are contained the the `memberid` field in the `posts` table.

 

Does this make any kind of sense to anyone?

 

Can anyone help me? Been up for 7 hours trying to do this, but no where fast

 

Any help would be ace

 

Thanks in advance

 

Ed

Link to comment
Share on other sites

Your setup confuses me...

 

when you put

`POSTS` - TABLE

ID      TITLE     MEMBERID
2       Holiday   4
3       Travel    3
4       Boats     4

 

but in the table above it, travel's memberid was 9. Also, you said you're looking for 1/3/4(in your example) and you have 4/3/4 listed as the results you expect to get.

Link to comment
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.