如何根据mysql中多个单词的单个单词显示表中的记录

时间:2013-09-05 07:40:53

标签: mysql

我有一张表如下

第1行:

did: 1
brand_name: Aarther P (100+500)
generic: Paracetamol, Aceclofenac
tradename: Aarther P (100+500)
manfactured: Rekvina Pharmaceuticals
unit: 500mg/100mg
type: Tablet
quantity: 10Tablet
price: 27.9

第2行:

did: 2
brand_name: Aarther-P
generic: Aceclofenac, Paracetamol
tradename: Aarther-P
manfactured: Rekvina Pharmaceuticals
unit: 100mg/500mg
type: Tablet
quantity: 10Tablet
price: 27.9

如果我根据像'扑热息痛'这样的通用搜索记录,我想按如下方式显示结果:

第1行:

did: 1
brand_name: Aarther P (100+500)
generic: Paracetamol
tradename: Aarther P (100+500)
manfactured: Rekvina Pharmaceuticals
unit: 500mg/100mg
type: Tablet
quantity: 10Tablet
price: 27.9

第2行:

did: 2
brand_name: Aarther-P
generic:  Paracetamol
tradename: Aarther-P
manfactured: Rekvina Pharmaceuticals
unit: 100mg/500mg
type: Tablet
quantity: 10Tablet
price: 27.9

我该怎么做?

3 个答案:

答案 0 :(得分:0)

如果您想获得表格的前两个记录,那么

select * from table limit 2;

如果打算获得其通用列值为Paracetmol的所有记录,那么

select * from table where generic='Paracetmol';

答案 1 :(得分:0)

select `did`, `brand_name`, 'Paracetamol' as `generic`, `tradename`, 
`manfactured`, `unit`, `type`, 
`quantity`, `price` from table1 where 
find_in_set ('Paracetamol',generic) 
or find_in_set (' Paracetamol',generic)

<强> SAMPLE FIDDLE

答案 2 :(得分:0)

试试这个

SELECT * FROM table WHERE generic LIKE '%paracetamol%'

这将选择在通用行中具有'parcetamol'的任何记录。它还将选择具有“扑热息痛”的记录和任何组合中的任何其他数据,例如:

'扑热息痛,asprin' 'codine,parcetamol' 'asprin,paracetamol,asprin'