Database Administrators Asked by Slim on January 3, 2021
Figure a table with two columns: id
, catId
How to select the records having the same catId
than the record having id
= 3?
Example:
id catId
1 3
2 4
3 4
4 4
5 3
Input: 3
Then catId of {id = 3} is 4
Then count of records having {catId = 4} is 3
Output: 3 records
SELECT COUNT(*)
FROM table t1
JOIN table t2 USING (catId)
WHERE t1.id = 3
If id
column is not unique then
SELECT COUNT(DISTINCT t2.id)
FROM table t1
JOIN table t2 USING (catId)
WHERE t1.id = 3
Correct answer by Akina on January 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP