Various Inner Join with Where SQL

Asked

Viewed 27 times

-1

Hello! I’m new with sql, I’m trying to do two joins, but after putting Where in the first, it appears that the second is with syntax error, but if I take Where, or the second Join, it returns the information

select nome, ncm, custo1, codigo_EAN, preco, tributacao from produto 
inner join produtopreco
    on produto.codigo = produtopreco.produto__codigo  
        where tabelapreco__ide = '11627049-F321-42DE-A3ED-4101BADDBC32'
inner join classeimposto
    on Produto.Classe_Imposto = classeimposto.codigo

1 answer

0


The problem is that it is not respecting the order of the clauses SQL of command SELECT. You can add many JOINS, but the JOIN of this outside of your query is being done within clause FROM, that is, in the origins of the tables, and the WHERE may only appear when the clause is over FROM, thus:

select nome, ncm, custo1, codigo_EAN, preco, tributacao 
  from produto 
 inner join produtopreco
    on produto.codigo = produtopreco.produto__codigo  
 inner join classeimposto
    on Produto.Classe_Imposto = classeimposto.codigo
where tabelapreco__ide = '11627049-F321-42DE-A3ED-4101BADDBC32'

Then you have to follow an order, SELECT, FROM, WHERE, GROUP BY, ORDER BY, etc, see the complete structure of the command SELECT and its clauses: https://docs.microsoft.com/pt-br/sql/t-sql/queries/select-transact-sql?view=sql-server-ver15

  • Got it! Thanks a lot for the clarification!

  • for nothing, do not forget to vote in the question or accept if she solved your doubt :)

Browser other questions tagged

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