- Messages
- 5,257
- Reaction score
- 97
- Points
- 48
I have two tables:
feed:
- id
- user_id
- content
friends:
- id
- user_id
- user2_id
Say (for example) that friends contains the following data:
0, 1, 4
1, 1, 6
2, 1, 12
3, 6, 1
3, 4, 1
3, 1, 15
3, 12, 6
feed contains the following data:
0, 1, 'Lorem Ipsum'
1, 2, 'Hello world!'
2, 1, 'What?'
3, 4, 'Bla'
4, 7, 'Test'
I want to get all items from the feed that are from friends. For example, if the current user id is 1, I want to get all the feed info from users 4, 6, 12 and 15 (and themselves):
0, 1, 'Lorem Ipsum'
2, 1, 'What?'
3, 4, 'Bla'
How would I do this using SQL? It should be portable SQL, usable in MySQL, Firebird etc.
~Callum
feed:
- id
- user_id
- content
friends:
- id
- user_id
- user2_id
Say (for example) that friends contains the following data:
0, 1, 4
1, 1, 6
2, 1, 12
3, 6, 1
3, 4, 1
3, 1, 15
3, 12, 6
feed contains the following data:
0, 1, 'Lorem Ipsum'
1, 2, 'Hello world!'
2, 1, 'What?'
3, 4, 'Bla'
4, 7, 'Test'
I want to get all items from the feed that are from friends. For example, if the current user id is 1, I want to get all the feed info from users 4, 6, 12 and 15 (and themselves):
0, 1, 'Lorem Ipsum'
2, 1, 'What?'
3, 4, 'Bla'
How would I do this using SQL? It should be portable SQL, usable in MySQL, Firebird etc.
~Callum