-1

I have a query for which I am giving a list of items as input, the item list contains duplicate values.

select * from ITEM  where ITEM_NUMBER in ('15','41', '15','41');

the resulting output contains 2 rows with

ITEM_NUMBER 15

and

41

I want a query, which returns 4 rows with duplicate values.

2
  • Use a left join instead of in. Commented Feb 9, 2018 at 13:29
  • Use set collection to store values. Then iterate set create query text Commented Feb 9, 2018 at 13:30

2 Answers 2

0

This is one option using join:

select *
from items a
join (select item_number
      from items  
      group by  item_number
      having count(*) > 1) b
on a.item_number = b.item_number;

Adapted from an answer in this link: Show all duplicated rows

Sign up to request clarification or add additional context in comments.

Comments

0

Here's a solution using UNION and TOP

select * from 
(select top 2 * from item where item_number=15) 
union all select * from 
(select top 2 * from item where item_number=41);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.