Suppose I have a table with threadid
and itemid
in it. There can be multiple entries of the itemid
with the same threadid
value...
The query:
SELECT DISTINCT
THREADID,
ITEMID
FROM THREADS
WHERE THREADID IN (SELECT DISTINCT THREADID FROM THREADS WHERE ITEMID = 10151)
yields:
THREADID ITEMID
----------- --------------------
149 10000
149 10076
149 10123
149 10151
149 10225
149 10227
149 10243
149 10245
149 10282
149 10310
149 10311
149 10312
149 10350
2000 10151
2000 10243
How can I wrap that in another query with group and order by query to get:
THREADID ITEMID
------------- ----------
149 13
2000 2