Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

There should be only two results, but why is it repeated three times?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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;

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading