Problem with selection in Mysql

Asked

Viewed 41 times

2

Guys I’m starting in this business and having difficulty in selecting in more than one table.

My selection command was as follows:

Table 01:

select * from veiculo;
|id_veiculo|modelo|cor|placa|chassi|renavam|combustivel|ano|hp|id_proprietario|id_uf|id_fabricante| 

|101001|Logan|Preta|JHE-3814|1234BFBF12|DF1234BR1234|GASOL/ALCOOL|2012|77|100|1|1010|
|101002|Corolla|Prata|JHJ-0007|2222BFBF22|DF4321BR4321|GASOLINA|2007|107|101|2|1011|
|101003|Strada|Vermelha|JHA-1221|3333BFBF11|MG0202BR4321|ALCOOL|2015|132|102|3|1012|

Table 02:

select * from fabricante;
|id_fabricante|nome|presidente|observacoes

|1010|Pedro Motta|RENAULT|Presidente da Renault em São Paulo e Rio de Janeiro|
|1011|Silvia Santos|TOYOTA|Presidente da Toyota em Brasília, Porto Alegre e Campo Grande|
|1012|Fausto Silva|FIAT|Presidente da Fiat no Brasil

This SQL is giving error:

SELECT t1.*,t2.* FROM veiculo t1, fabricante t2 
WHERE t1.id_fabricante= t2.id_fabricante AND t1.veiculo 
LIKE  "JHJ%" AND t1.ano <> 2000 AND t1.combustivel="GASOLINA" AND t2.presidente="TOYOTA";

ERROR 1054 (42S22): Unknown column 't1.vehicle' in 'Where clause'

Where is the error?

1 answer

1


The error is very clear: the table veiculo does not have the column veiculo. Apparently, you wanted to look for t1.placa instead of t1.veiculo. The correct query would be:

SELECT t1.*,t2.*FROM veiculo t1, fabricante t2 
WHERE t1.id_fabricante = t2.id_fabricante AND t1.placa LIKE "JHJ%" 
AND t1.ano <> 2000 AND t1.combustivel = "GASOLINA" AND t2.presidente = "TOYOTA";
  • caracas, I’m hours trying to find the error.

  • Thank you very much

  • 1

    @Davinascimento how good it was solved... can mark the answer as correct? :)

  • Not yet consig

Browser other questions tagged

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