Query Logic SQL

回眸只為那壹抹淺笑 提交于 2019-12-11 20:46:06

问题


I have a table that contains this data.

main_id main_name other_name
   1      aa aa     bb bb 
   1      aa aa     cc cc
   2      bb bb     aa aa
   2      bb bb     cc cc
   3      cc cc     aa aa
   3      cc cc     bb bb

I have a field where user will search by name, when user searches for name the query should get data like main_name and other_name.

What I have tried so far is:

select where main_name like $data_entered or other_name like $data_entered

the result of this gives me

main_id main_name other_name
   1      aa aa     cc cc
   3      cc cc     aa aa
   3      cc cc     bb bb

I need to include:

main_id main_name other_name
   1      aa aa     bb bb

id did a query like this:

select where main_name like $data_entered or (main_name like $data_entered or 
other_name like $data_entered)

but still can't get:

main_id main_name other_name
   1      aa aa     bb bb

Any help would be appreciated

By the way, I'm coding php, with codeigniter framework.

来源:https://stackoverflow.com/questions/26648633/query-logic-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!