phpsqlpdotwitter-follow

Using two WHERE statements for different tables


I have build a follow system but that system displays all members who are even temporarily deactivated, for disabling deactivated members from showing in areas such as followers or following I have added a column 'closed' in members table which is initially set to no and when a member wants to temporarily deactivate his profile this no is updated to yes. Now my idea is to join the select statement which selects members followed or following from follow table with members with the column closed set to no in members table so my system displays only activated members.

My select statement is:

SELECT * FROM follow WHERE uid=:memberid

I tried but get syntax error for this:

SELECT * FROM follow INNER JOIN members on members.memberid=follow.uid WHERE uid=:memberidid WHERE closed=no

Solution

  • Instead of using WHERE twice, you can use AND for the 'second' WHERE-clause.

    SELECT * FROM `follow` INNER JOIN `members` ON `members`.`memberid` = `follow`.`uid` WHERE `uid` = :memberidid AND `closed` = "no"