A
A
Artem2016-08-26 10:59:48
SQL
Artem, 2016-08-26 10:59:48

How to add a column from another table to the selection?

Hello. There are two tables.
The first is
trip_id, courier_id, destination_id, trip_start, trip_end
And the second is
id, full name
I want to select everything that is greater than trip_start, less than trip_end, and add the full name of the courier from the second table to this.
I'm trying something like this, but the selection is empty:

SELECT * FROM schedule JOIN couriers ON schedule.courier_id = couriers.`full name` WHERE `trip_start` > '$2015-06-15' AND `trip_end` < '2016-01-01'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
davidnum95, 2016-08-26
@proudmore

SELECT schedule.*, couriers.full_name FROM schedule LEFT  JOIN couriers ON couriers.id = schedule.courier_id WHERE `trip_start` > '$2015-06-15' AND `trip_end` < '2016-01-01'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question