Checkpoint 30.4.1.
Write a query to find out how many trips were started at (had a
start_station of) 'Adams Mill & Columbia Rd NW'?
trip_data table to find the station with the longest overall ride:
FROM clause):
bikeshare_stations table, but to find the right station, we need to use the duration that is a part of the other trip_data table. Doing two queries to get the data we need is kind of inconvenient.
JOIN keyword. JOIN is used to merge the columns in one table with the columns in another table.
trip_data are joined with the records that talk about that same station number in bikeshare_stations. To specify how to JOIN tables, we must use an ON clause that specifies which column in the first table to match with which column in the second table. To name the columns, we use dot syntax: table_name.column_name. The full syntax for a JOIN looks like this:
SELECT
* -- or whatever
FROM first_table
JOIN second_table
ON
-- look for records where the value in column_A in the first_table
-- match the value in column_B in the second table
first_table.column_A == second_table.column_B
-- WHERE or ORDER BY if we want
trip_data as the first table and bikeshare_stations as the second. In trip_data, the station number is stored as start_station. In bikeshare_stations those same values are stored in the station_id column.
* to name so that we just get that column. If we want to be really clear about what column we are talking about (or if both tables had a column called name so we had to be more specific), we could write it as bikeshare_stations.name because it is the name column from bikeshare_stations.
end_station field from the trip_data table to the station_id field in the bikeshare_stations table.
name column in the two tables, we could just say name. But it never hurts to be clear about which table we are talking about once we start joining data.
start_station of) 'Adams Mill & Columbia Rd NW'?
COUNT(*) to find the total number of stations.
status in bikeshare_stations. It is stored as a string, so use 'closed' as the value in your WHERE.