简体   繁体   English

当字段输入以#开头时,从sql中排除特定数据

[英]Excluding specific data from sql when field entry begins with #

I need to modify this sql query 我需要修改此sql查询

"SELECT 
    c.categories_id,
    categories_name
FROM 
    " . TABLE_CATEGORIES ." c, 
    " . TABLE_CATEGORIES_DESCRIPTION . " cd  
WHERE c.categories_id  = cd.categories_id 
AND parent_id=" . App_DefaultCategoryID . " 
AND categories_status=1 
AND cd.language_id = " . $language_id . " 
ORDER BY sort_order, categories_name ";

so that it does not include results where the categories_name field contains any data beginning with a #, for instance #Curiosities. 因此它不包括类别类别名称字段包含任何以#开头的数据(例如#Curiosities)的结果。

How can i exclude such data from the query? 如何从查询中排除此类数据?

This can be done by using a NOT LIKE statement, ie by adding the following to the WHERE criteria 这可以通过使用NOT LIKE语句来完成,即,将以下内容添加到WHERE条件中

AND categories_name NOT LIKE '#%'

As an addition, it may be an idea to add the table prefix to all field names for clarity later on. 另外,为稍后清楚起见,将表前缀添加到所有字段名称可能是一个想法。 I don't know which tables each column comes from though so you're on your own on that. 我不知道每列来自哪个表,所以您就此靠自己了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM