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
https://forums.phpfreaks.com/topic/111235-solved-query-issue-crossing-tables/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.