If else on WHERE clause

前端 未结 5 1845
栀梦
栀梦 2020-12-09 01:53

I\'ve this query:

SELECT  `id` ,  `naam` 
FROM  `klanten` 
WHERE (
`email` LIKE  \'%@domain.nl%\'
OR  `email2` LIKE  \'%@domain.nl%\'
)

But

5条回答
  •  Happy的楠姐
    2020-12-09 02:20

    Here is a sample query for a table having a foreign key relationship to the same table with a query parameter.

    SET @x = -1;
    SELECT id, categoryName 
    FROM Catergory WHERE IF(@x > 0,category_ParentId = @x,category_ParentId IS NOT NULL);
    

    @x can be changed.

提交回复
热议问题