Skip to content
Advertisement

inner join with condition on joined table

I’m trying to collect data using the following query:

SELECT * 
FROM `table1` AS `t1` 
INNER JOIN `table2` AS `t2` 
  ON `t1`.`id`=`t2`.`id` 
WHERE  `t2`.`name`='myname'

It looks like the WHERE condition is ignored. Is it possible to apply the WHERE condition on the joined table?

Advertisement

Answer

The ‘Where’ clause should not be ignored in this condition as well.

If you want to exclude the where condition, you can do it by writing the condition as part of the ON Clause.

SELECT * 
FROM `table1` AS `t1` 
INNER JOIN `table2` AS `t2` 
  ON `t1`.`id`=`t2`.`id`  
    and `t2`.`name`='myname'
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement