Using WHERE with INNER JOIN [duplicate]

2

Is there a way to use WHERE to make a SELECT with INNER JOIN ?

My case is this:

SELECT CodCli, NomeCli 
FROM tbvendas 
  INNER JOIN tbclientes 
  ON tbvendas.CodCli = tbclientes.AutoCod

I would like to put a WHERE status = "debitado" where status is in tbvendas

    
asked by anonymous 17.11.2016 / 15:57

2 answers

4

You can add the WHERE clause before or after Inner Join

SELECT CodCli, NomeCli 
FROM tbvendas 
    INNER JOIN tbclientes 
    ON tbvendas.CodCli = tbclientes.AutoCod
WHERE status = 'debitado'

To add the WHERE clause in the clients, use the AND after the ON comparison

SELECT CodCli, NomeCli 
FROM tbvendas 
    INNER JOIN tbclientes 
    ON tbvendas.CodCli = tbclientes.AutoCod
    AND ...
WHERE status = 'debitado' 

there you can also filter the content of the clients

    
17.11.2016 / 16:12
5

Just add the where clause in the query

SELECT CodCli, NomeCli 
FROM tbvendas 
  INNER JOIN tbclientes 
  ON tbvendas.CodCli = tbclientes.AutoCod    
Where Status = 'debitado'
    
17.11.2016 / 16:03