Kiran Gopalakrishnan
Kiran Gopalakrishnan

Reputation: 322

selecting rows from a table based on the matching results from another table

i have 2 tables in a database named "posts", "connections"

with strucure as given in images

POSTS

enter image description here

CONNECTIONS

enter image description here

i have a variable that holds a value ,lets assume variable "a" ,it has to be checked against the field "following" in the connections table ,and the resulting rows should be used to select only those rows from the table "POSTS" where follower field is equal to the post_by field ,am really stuck on this one,could use a little help

Upvotes: 1

Views: 41

Answers (1)

Nouphal.M
Nouphal.M

Reputation: 6344

Try this query :

SELECT * FROM posts AS P
INNER JOIN connections AS C ON C.follower = P.post_by
WHERE C.following = "a"

Upvotes: 2

Related Questions