The users_groups table
userid groupid
10 4
10 2
6 4
11 4
12 2
13 2
$query="SELECT count(*) FROM `users_groups`
WHERE `userid`='$fromuserid'
AND `groupid` in (
SELECT `groupid`
FROM `users_groups`
WHERE `userid`=`$touserid
);";
$fromuserid=10
$touserid=11
The query to find out userid 10 and userid 11’s common groupid which is 4. but my query is returning null. Any mistake with the query?
You have a syntax error in your query. There is an extra backtick in the subselect.
It should be this: