选择Record with common column field

时间:2015-07-11 11:16:05

标签: sql sqlite

我有以下表重复id。我希望所有记录都有重复的id

CREATE TABLE Student1
    (`id` int,`status` int,`amount` int , `Name` varchar(10), `date` varchar(55))
;

INSERT INTO Student1
    (`id`,`status`,`amount`, `Name`, `date`)
VALUES
    (1,0,4500, 'ram', '04/02/2012'),
    (2,0,2000, 'shyam', '05/09/2013'),
    (2,0,6500, 'radhe', '11/11/2014'),
    (2,0,8000, 'radheshyam', '15/11/2013'),
    (4,0,1500, 'ghanshyam', '08/11/2014')
;

id  status  amount  Name         date
1   0       4500    ram         04/02/2012
2   0       2000    shyam       05/09/2013
2   0       6500    radhe       11/11/2014
2   0       8000    radheshyam  15/11/2013
4   0       1500    ghanshyam   08/11/2014

查询:

Select * from Student1 group by id having count(*)>1

结果:

id  status  amount  Name    date
2   0       2000    hyam    05/09/2013

预期结果:

   id status    amount     Name        date
   2    0       2000      shyam      05/09/2013
   2    0       6500      radhe      11/11/2014
   2    0       8000    radheshyam   15/11/2013

1 个答案:

答案 0 :(得分:1)

尝试,

SELECT * FROM Student1
   where id in (SELECT id FROM Student1 GROUP BY id HAVING count(*)>1)