I have a table which contains a list of livestock ("livestock"), this gets regularly updated and changed. I also have a second table ("description") containing two columns "Scientific" and "Description".
I need to select the Description field from the description table when the Scientific field in both tables matches but not sure how best to do this.
Hope this makes sense, any help is much appreciated
Since you have mismatches between two of your tables (meaning not all rows in livestock
have respective rows in description
) you most likely have to use an OUTER JOIN
(LEFT
or RIGHT
) to achieve your goal
SELECT l.*, d.description
FROM livestock l LEFT JOIN description d
ON l.scientific = d.scientific
Here is SQLFiddle demo
Further reading
On a side note: When asking query related questions, especially when you don't provide your version of the query, please at least help those who want to help you and provide your table(s) schema, sample data, and desired output based on it. Better yet spend one minute and create sqlfiddle with your sample data.
Assuming table_a is the name of the livestock table and table_b is the table with the description in it, you'll want to join the tables on the 'scientific' field.
SELECT table_a.*, table_b.Description
FROM table_a
JOIN table_b ON table_a.Scientific = table_b.Scientific
You'll want to replace table_a
and table_b
with the correct table names.