如果字段包含来自另一个记录的值,则删除所有行

时间:2016-07-10 14:16:29

标签: sqlite

我有这样一张桌子:

Name        Code
-------------------
John        1235
John        1235/11
John        1236/12
Mary        2500
Mary        2500/8
Mary        3600
Mary        3600/9

我想删除代码值包含在另一行中的所有行。 在示例中,我想删除这些记录:

Name        Code
-------------------
John        1235
Mary        2500
Mary        3600

2 个答案:

答案 0 :(得分:0)

这是一种方法:

delete from t
    where exists (select 1
                  from t t2
                  where t2.value like t1.value || '/%'
                 );

如果您不想实际删除记录,只是希望查询不返回它们:

select *
from t
where not exists (select 1
                  from t t2
                  where t2.value like t1.value || '/%'
                 );

这些假设(如示例中),“包含”实际上意味着“从”/“开始。

答案 1 :(得分:-1)

// you need to know the `length` of `oJdDetails.topics` 
$scope.rates = new Arryay(oJdDetails.topics.length).fill(0); // initialisation of array with `0` value
$scope.displayStars = new Arryay(oJdDetails.topics.length).fill(false);; // initialisation of array with `false` value
$scope.fngetQList = function (topics, index) {
    $scope.displayQList = true;
    $scope.displayStars[index] = true;
    $scope.sTopics = topics;
    $scope.index = index;
    getCandidateInterviewListService.fnGetQList(topics).then(function(response) {
        $scope.aQuestionList = response;
        console.log($scope.aQuestionList);
    });
};