[英]where clause in inner join
I am generating a query. 我正在生成查询。 I have two tables name: flights and destinations.
我有两个表名:航班和目的地。 In a flight table, I have column: id, departure, destination, price, airline, class and in destinations table that i have column:
id, destination, country, region.
在航班表中,我有列:ID,出发地,目的地,价格,航空公司,舱位,而在目的地表中我有列:
id, destination, country, region.
Now I want to get flights detail whose region is "Europe"
. 现在,我想获取区域为
"Europe"
航班详细信息。 I am doing inner join
. 我正在做
inner join
。 My query is this: 我的查询是这样的:
SELECT *
FROM `flights`
INNER JOIN destinations ON flights.destination = destinations.destination
where region= 'europe'
Its giving me null result. 它给我空结果。 if I remove (
where region= 'europe'
) from my query then it gives me the results of all the columns of flights and destinations. 如果我从查询中删除(
where region= 'europe'
),那么它将为我提供航班和目的地所有列的结果。
Please help me out 请帮帮我
Try this 尝试这个
SELECT *
FROM `flights`
INNER JOIN destinations
ON flights.destination = destinations.destination
where LOWER(region) = 'europe'
I note that you say 'Europe'
is the region. 我注意到您说
'Europe'
是'Europe'
。 MySQL can be case-sensitive, depending on the collations being used for the database and table (but not by default). MySQL可能区分大小写,具体取决于用于数据库和表的排序规则(但默认情况下不是)。 So, I would start with comparing the proper case:
因此,我将从比较合适的情况开始:
SELECT *
FROM flights f INNER JOIN
destinations d
ON f.destination = d.destination
WHERE d.region = 'Europe';
If that doesn't work, then strange characters might have crept into the region
column. 如果这不起作用,则可能是奇怪的字符潜入了“
region
列。 You can try: 你可以试试:
WHERE lower(d.region) like '%europe%'
Since you are using an inner join, you can specify the region as part of the join conditions, like this: 由于使用的是内部联接,因此可以将区域指定为联接条件的一部分,如下所示:
SELECT *
FROM `flights`
INNER JOIN destinations ON flights.destination = destinations.destination
AND destinations.region = 'europe'
Does the Flights.Destination value store the Id of the Destination table? Flights.Destination值是否存储“目标”表的ID? You may need to adjust the join to
您可能需要将联接调整为
flights.destination = destinations.Id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.