我在MySql DB中有两个名为'Patients'和'Country'的表。患者表包含
'name','dob',postcode','address', 'country_id'
等
国家表有
'id' and 'country_name'
专栏。
现在,我希望用户输入患者姓名,邮政编码或国家/地区的任何内容,并获取所需患者的结果/数据。
为实现这一点,我能想到的一种方法是使用连接执行查询。另一方面,我想问一下,将搜索变量(即名称,邮政编码和国家/地区)存储在具有全文类型的列中的方式是一种很好的方法,就像这个'name_postcode_country'一样,当用户输入搜索变量时我在新创建的列上执行全文搜索。
或者还有其他更好的方法,我应该考虑。
将所有这些信息保存在单个列中并不是一个好主意,您可以将这种组合与加入所提到的表的SELECT结合使用:
select p.name, p.dob, p.postcode, p.address,
c.country_name
from Patients p
inner join Country c
on ( p.country_id = c.id )
where ( upper(name) like upper('%my_name_string%') )
or ( upper(postcode) like upper('%my_postcode_string%') )
or ( upper(country) like upper('%my_country_string%') );
你需要使用upper
或lower
pseudocolumns来解决区分大小写问题。