Skip to content
Advertisement

How to select columns after inner join

Once I have joined two dataframes by a specific column I then want to select specific columns from this table – how can I do this?

I have tried the following:

SELECT * 
FROM 
    land_birds
INNER JOIN
    sea_birds
ON
    land_birds.colour = sea_birds.colour

SELECT
    colour,
    beak,
    size, 
    weight
FROM
    TABLE

However I get the following error:

near “SELECT”: syntax error

Advertisement

Answer

Instead of a second select, use the first one.

For example, this will get the name and flavor of each land and sea bird pair.

SELECT
  land_birds.nane, land_birds.flavor,
  sea_birds.name, sea_birds.flavor
FROM 
    land_birds
INNER JOIN
    sea_birds
ON
    land_birds.colour = sea_birds.colour

Note that because you’re joining two tables, you will get the columns of both tables in each row.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement