INNER JOIN with OR clause

2

I have the following select:

SELECT linha._id, 
       linha.numero_onibus, 
       linha.nome, 
       percurso.nome 
FROM linha
INNER JOIN percurso ON linha._id = percurso.id_linha
AND (linha.numero_onibus LIKE ? OR linha.nome LIKE ?) COLLATE NOCASE

When the linha.numero_onibus LIKE ? condition is false, the query returns no results. What do I have to do so that even if the linha.numero_onibus LIKE ? condition is false, it proceeds with the query and returns me the results of linha.nome LIKE ? ?

    
asked by anonymous 14.10.2014 / 03:24

1 answer

0

Quick response (you'll need to test):

 SELECT
 linha._id, 
 linha.numero_onibus, 
 linha.nome, 
 percurso1.nome as the_nome_caso_1,
 percurso2.nome as the_nome_caso_2

 FROM linha

 LEFT OUTER JOIN percurso as percurso1 ON linha._id = percurso1.id_linha
 AND linha.nome LIKE ?

 LEFT OUTER JOIN JOIN percurso as percurso2 ON linha._id = percurso2.id_linha
 AND linha.numero_onibus LIKE ? 

Then you will use the route table twice, but with "alias".

If you use INNER JOIN and the query gives a false result, it will not work.

    
14.10.2014 / 03:31