Using WHERE with INNER JOIN

Asked

Viewed 25,412 times

4

There is a way to use one WHEREto make a SELECTwith INNER JOIN ?

my case is this:

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

I’d like to put a WHERE status = "debitado" where the column status is in the tbvendas

2 answers

6

Just add the cloister where in consultation

SELECT CodCli, NomeCli 
FROM tbvendas 
  INNER JOIN tbclientes 
  ON tbvendas.CodCli = tbclientes.AutoCod    
Where Status = 'debitado'

6


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 tbclientes, use the AND after the ON comparison

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

then you can also filter the content of TBCLIENTES

  • 1

    It is possible to filter the tbclientes for where same. The AND after the ON is to be used when condition is part of Inner Join.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.