MySQL query to count occurrences from multiple tables

I have a problem when I have to select everything from one table (persons) then count how many objects they own by counting their occurrences on other tables (pens, chairs, books) The current data is as followed: select * from persons; +—-+——-+ | id | name | +—-+——-+ | 1 | Alex | | 2… Read More MySQL query to count occurrences from multiple tables

SELECT * FROM tblPosts WHERE tblPosts.usersID = (SELECT tblFriends.friendsID WHERE tblFriends.myID = '$myID') ORDER BY tblPosts.date DESC;

SELECT * FROM tblPosts WHERE tblPosts.usersID = (SELECT tblFriends.friendsID WHERE tblFriends.myID = ‘$myID’) ORDER BY tblPosts.date DESC; This doesn’t through an error but it also doesn’t work. I think I need a join statement maybe? There are several fields in tblPost. ID, Comment, Date, userID, etc… Using my $myID variable I want to output <<<while($row… Read More SELECT * FROM tblPosts WHERE tblPosts.usersID = (SELECT tblFriends.friendsID WHERE tblFriends.myID = '$myID') ORDER BY tblPosts.date DESC;

Using SQL check to see if an ID in Table A exists in Table B. If that ID exists in Table B return corresponding value

I have a table call it Table A. Table A with an ID column ID1 associated with a row. That table looks like the following: ID1 A1.0 B2.0 C3.0 A1.0 … I have a second table call it Table B that has an ID and a corresponding value. That table looks like the following: Value… Read More Using SQL check to see if an ID in Table A exists in Table B. If that ID exists in Table B return corresponding value