I have two tables with similar information. Let’s call them items_a and items_b. They should be one, but they are coming from different sources, so they aren’t. When I full-join the two table, some rows end up with data from either one or both tables. One of the columns in both tables is category_id. I would like to cross the combined table with the categories table using category_id. However, I have two category_id columns now (one from items_a and one from items_b). Is there a way to merge the two columns into one?
I hope this isn’t too confusing of a question.
Specifying the columns on your query should do the trick:
should do the trick with regards to picking the columns you want.
To get around the fact that some data is only in items_a and some data is only in items_b, you would be able to do:
The coalesce function will return the first non-null value, so for each row if col1 is non null, it’ll use that, otherwise it’ll get the value from col2, etc.