Answer the question
In order to leave comments, you need to log in
How to display records with the same code in a sql query?
How to display records in sql query in which the order code is the same?
For example, there is a table
Order_code Name
1. Muromets
2. Nikitich
2. Muromets
3. Plyasovaya
3. Nikitich
How to display records with code 2 and records with code 3 in two separate tuples
If anyone is interested. Solved the problem using a function in SQLite: GROUP_CONCAT()
Answer the question
In order to leave comments, you need to log in
-- Создаем временную таблицу для реализации примера
Create table #tt1
(_Code nvarchar(10),
_Name nvarchar(100))
-- Наполняем временную таблицу тестовыми данными
Insert into #tt1
Select '1.', 'Муромец'
Insert into #tt1
Select '2.', 'Никитич'
Insert into #tt1
Select '2.', 'Муромец'
Insert into #tt1
Select '3.', 'Плясовая'
Insert into #tt1
Select '3.', 'Никитич'
-- Выбираем строки где поле _Code повторяется 2 и более раз
Select
t1._Code,
t1._Name,
t3.Counter
From
#tt1 as t1
inner join(
Select
t2._Code,
COUNT(t2._Name) as counter
from #tt1 as t2
group by
t2._Code
Having COUNT(t2._Name) >1
) as t3
on t1._Code = t3._Code
-- Удаляем временную таблицу.
drop table #tt1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question