MySQL - If It Starts With A Number Or Special Character

前端 未结 3 2100
独厮守ぢ
独厮守ぢ 2020-12-15 01:21
SELECT * 
FROM `thread` 
WHERE forumid NOT IN (1,2,3) AND IF( LEFT( title, 1) = \'#\', 1, 0)
ORDER BY title ASC

I have this query which will select

3条回答
  •  Happy的楠姐
    2020-12-15 01:49

      SELECT t.* 
        FROM `thread` t
       WHERE t.forumid NOT IN (1,2,3) 
         AND INSTR(t.title, '#') = 0
    ORDER BY t.title
    

    Use the INSTR to get the position of a given string - if you want when a string starts, check for 0 (possibly 1 - the documentation doesn't state if it's zero or one based).

提交回复
热议问题