I have two tables:
product is a consumer product (ex. iPhone X), and a
posting is a listing for a product on an online marketplace (ex. eBay posting). A single product has zero or more associated postings.
Is there any way to select only postings which have a “sibling”? ie. Select all postings whose
product column is equal to any other postings’
SELECT * FROM postings a INNER JOIN products b ON a.product = b.id WHERE COUNT(b) > 0
I am wondering your inner join should only do the trick, but in case I am missing something you can try this
With a as ( SELECT a.*,b.*, count(*) over(Partition by b.id) cnt FROM postings a INNER JOIN products b ON a.product = b.id ) Select * from a where cnt > 0