Good evening, people help please. There is a Client table with id_client , phone_client , name_client , taxipark_id_taxipark . There is a Taxipark table with id_taxipark , name_taxipark , phone_taxipark . There is a client "Maxim". It is necessary to withdraw a taxi company serving the "Maxim". Request:

 select name_taxipark from taxipark where id_taxipark in (select taxipark_id_taxipark from client where name_client.client = 'Maxim'); 

Crashes:

ERROR 1054 (42S22): Unknown column 'name_client.client' in 'where clause'

Help please solve the problem.

  • replace name_client.client with client.name_client . First, the name of the table is indicated, and then its field is Viktorov
  • Thank you very much! - Maxim

1 answer 1

 select taxipark.name_taxipark from client, taxipark where client.name_client = 'Maxim' AND client.taxipark_id_taxipark = taxipark.id_taxipark 

It seems not to be confused with your names ...


In general, there is a proposal to make the names of the columns shorter. There will be no problems (confusion) in the future. But it will be more readable ... and familiar to everyone ...

 taxiparks [id, name, phone] clients [id, name, phone, taxipark_id] 

And the query will then look like this.

 SELECT taxiparks.name FROM taxiparks, clients WHERE taxiparks.id = clients.taxipark_id AND clients.name = 'Maxim' 

Correction.

It is better to write with inner join or, if necessary, with left join.

 SELECT taxiparks.name FROM clients LEFT JOIN taxiparks ON clients.taxipark_id = taxiparks.id WHERE clients.name = 'Maxim' 
  • from client, taxipark - have you forgotten like a JOIN, or does it also work without it? - Victor
  • It works the same way, but you are right, it is better to write with joins. Yes, yes, left join can be done .. it all depends on your database schema and needs. I will add option with left join to the answer. - Eugene
  • @ Victor The comma operator in the FROM clause, most SQL dialects is equivalent to INNER JOIN, only join conditions are written with all others in the WHERE clause. - Mike