SQL查询中的问题 [英] issue in sql Query
问题描述
我在表中有一列,该列名称为项目,其中包含这样的值
I have an column in table where this column name is items it contains value like this
itemID items
1 school,college
2 place, country
3 college,cricket
4 School,us,college
5 cricket,country,place
6 football,tennis,place
7 names,tennis,cricket
8 sports,tennis
现在我需要写一个搜索查询
Now I need to write a search query
例如:如果用户在文本框中输入板球"并单击按钮,则需要在项目栏中查看板球.
Ex: if the user types 'cricket' into a textbox and clicks the button I need to check in the column items for cricket.
在表中,我有3行,其中项目列中的 cricket
(ItemId = 3、5、7)
In the table I have 3 rows with cricket
in the items column (ItemId = 3, 5, 7)
如果用户键入 tennis,cricket
,那么我需要获取与任一记录都匹配的记录.所以我需要获得5行(ItemId = 3、5、6、7、8)
If the user types in tennis,cricket
then I need to get the records that match either one. So I need to get 5 row (ItemId = 3, 5, 6, 7, 8)
如何为此要求编写查询?
How do I write a query for this requirement?
推荐答案
您需要重新设计数据库,因为这是一个非常糟糕的结构.您永远不要在字段中存储逗号分隔的列表.首先考虑一下您需要的字段,然后设计一个合适的数据库.
You need to start by redesigning your database as this is is a very bad structure. You NEVER store a comma delimited list in a field. First think about waht fields you need and then design a proper database.
这篇关于SQL查询中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!