Bob Bob - 6 months ago 12
MySQL Question

MySQL select statement from two tables

A common scenario I imagine, but I can't seem to find the terminology to find this answer...

I have two tables, one referencing the other like so:

topics
------------
title
category_id

categories
------------
category_id
category_title


How would I write a query to select the title and category_title of a topic, instead of the id?

Answer

How about something like

SELECT  title, 
        category_title
FROM    topics t inner join
        categories c    ON t.category_id = c.category_id

Have a look at JOIN Syntax