显示拖动列中具有重复值的记录的第一个实例

时间:2017-06-14 05:56:05

标签: mysql duplicates

我在名为advertisements的表格中有这些值:

id         sitecatid      locationid
1             12            3
2             12            6
3             12            8
4             12            8 
5             12            8 
6             10            18 
7             13            20
8             14            21

我想这样返回结果:

sitecatid      locationid
    12            3
    10            6
    13            8
    14            18
                  20
                  21

基本上我只想要具有唯一sitecatid的任何记录的第一个实例  和locationid。 我试过这个查询但结果不正确:

  SELECT DISTINCT sitecatid, locationid 
    FROM advertisements 
    WHERE MATCH (sitetitle,sitedescription) 
AGAINST ('$q' IN BOOLEAN MODE) AND status='approved' 

1 个答案:

答案 0 :(得分:1)

         Item     l     c     u
        <chr> <int> <int> <int>
1 “CostItem1”  1500  1900  2600
2 “CostItem2”  2400  3200  4400
3 “CostItem3”   500  1000  1500