'Exclude exact word on many columns dosn't work
I have two table category and products and I'm doing filtering with many methods on the rows.
This is my data :
Table Category :
Id Libelle Description 1 Animals dogs 2 Kids games
Table Product :
Id Name Category_Id 1 aaa kkk 2 2 bbb kkk 2
There is a FK between these two tables.
This is my first query I select rows and then I want to exclude the row if category.Libelle
OR Category.Description
match some word :
select distinct * from category cat
JOIN product pro on pro.Category_Id = cat.Id
where (MATCH (pro.Name)
AGAINST( 'kkk' IN BOOLEAN MODE))
AND
(concat(cat.Libelle , cat.Description)
NOT REGEXP '[[:<:]]kids[[:>:]]')
Here the result is not correct it returns 2 rows except that must return 0 rows why ?
The second query I want the same purpose but I will check with product.Name
:
select distinct * from category cat
JOIN product pro on pro.Category_Id = cat.Id
where (MATCH (pro.Name)
AGAINST( 'kkk' IN BOOLEAN MODE))
AND pro.Name NOT REGEXP '[[:<:]]bbb[[:>:]]'
Here I have as result one row that is it :
'2', 'kids', 'games', '1', 'aaa kkk', '2'
But I want to exclude that row also, so I want exclude the row of the category if any of the Name of list Product pro.Name
associated with Category_Id
contains exact word 'bbb', So I want a result of 0 row and not 1 row, How can I do it ?
Solution 1:[1]
What I did is to concat all columns of the parent table, in addition of all child rows associated grouped by method group concat :
select distinct cat.* , concat(coalesce(cat.Libelle , ' ') , ' ', coalesce(cat.Description, ' ') , ' ' , group_concat(distinct coalesce(pro.libelle , ' ') separator ' ')) as listConcat
And than Checking with HAVING
for all rows returned by the select :
HAVING listConcat RLIKE
Solution 2:[2]
Will a simple WHERE clause not work? e.g.
WHERE category.Libelle <> ‘kids’
AND Category.Description <> ‘kids’
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mecab dev |
Solution 2 | NickW |