Good evening, people please help.
There is a Client
table with id_client
, phone_client
, name_client
, taxipark_id_taxipark
columns. There is a table Taxipark
with columns id_taxipark
, name_taxipark
, phone_taxipark
. There is Client “Maxim”. It is necessary to withdraw the 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 ‘
Please help me solve the problem.
Answer 1
select taxipark.name_taxipark
from client, taxipark
where client.name_client = 'Maxim' AND
client.taxipark_id_taxipark = taxipark.id_taxipark
I don’t seem to be confused with your names …
In general, there is a proposal to make the column names shorter. There will be no further problems (confusion). But it will be more readable … and more familiar to everyone …
taxiparks [id, name, phone]
clients [id, name, phone, taxipark_id]
And the request will then look like this
SELECT taxiparks.name
FROM taxiparks, clients
WHERE taxiparks.id = clients.taxipark_id AND
clients.name = 'Maxim'
Bugfix.
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'