我正在研究一些搜索内容,问题是我可以选择多个选项,并希望根据它们创建我的查询。
如果有人能帮助我,我会很高兴。
我的主要搜索表是:
id
name
card_id
phone_numbre
country_id
futurecountry_id
ID是唯一的,名称是文本,card_id和phone_number都可以,我可以在我的桌子上找到它们,但问题是当我需要将数据提取到其他表格时,特别是country_id进入一个名为“country”的表,我在那里比较id以检查是否相同我带来了国家名称,是我咨询的同一个表获取country_id和futurecountry_id我真的不知道该怎么做
有人有任何想法吗?
P.S。好吧,也许我无法解释自己很好,我的问题是:
我有一个表格,你填写了一些数据并带给你个人信息,而不是字段origencountry和destinycountry的id我需要名字,例如,如果我发送origencountry = 10和destinycountry = 8我会这样做:
select *
from infotable,countrytable
where infotable.iddestinycountry = countrytable.id and infotable = 10
AND infotable.origencountry = countrytable.id and infotable = 8
查询似乎工作正常,但它不输出任何数据。 以我的餐桌国家为例:
id name
1 usa
2 uk
3 spain
和信息
id name origencountry destinycountry
1 john 1 2
答案 0 :(得分:0)
您可以使用LEFT JOIN或RIGHT JOIN。
例如:
SELECT c.country_id from country as c
LEFT JOIN futurecountry as fc ON c.country_id = fc.futurecountry_id
在此示例中,您只返回包含country和futurecountry_id键的国家/地区的结果
有关更多信息,请参阅此处:http://dev.mysql.com/doc/refman/5.0/fr/join.html