Reputation: 13
select a.m_num,a.filename,a.title,a.price,a.stock
from newboard a , cart b
where a.m_num = b.m_num and a.board_num = ANY(select board_num from cart where m_num = '82');
The result
FIELD1 | FIELD2 | FIELD3 | FIELD4 | FIELD5 |
---|---|---|---|---|
82 | NO1.png | car | 39000 | 1 |
82 | 0 | 0 | ||
82 | NO1.png | car | 39000 | 1 |
82 | 0 | 0 | ||
82 | NO1.png | car | 39000 | 1 |
Why is it repeating?
Upvotes: 0
Views: 43
Reputation: 46
Since inner join is working as Cartesian Product. To get distinct rows either use distinct keyword after select or use group by.
Example:
select a.m_num,a.filename,a.title,a.price,a.stock
from newboard a , cart b
where a.m_num = b.m_num
and a.board_num = ANY(select board_num from cart where m_num = '82')
group by a.m_num,a.filename,a.title,a.price,a.stock;
Upvotes: 1