
take the above as an output of a sample table,
I need an sql query which results “2” as the count from the table.
i’ve tried intially while sentby column upto 4, and was okay;
but more rows shows incorrect o/p. my older code is given
SELECT COUNT(*)/2
FROM
(SELECT sentby,sentto
FROM
(SELECT DISTINCT sentby, sentto FROM count_temp)
WHERE sentto IN
(SELECT DISTINCT sentby FROM count_temp )
AND sentby IN
(SELECT DISTINCT sentto FROM count_temp )
) ;
Thanks in advance:) and appreciated.
Your query:
test it at sqlfiddle
Also, simplifying: