[英]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? 如何编写查询以选择主题的标题和category_title而不是ID?
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 看看JOIN语法
您正在寻找的术语称为联接。
select title,category_title from topics,categories where title.category_id = categories.category_id;
试试这个查询
select t.title, c.category_title from topic t, categories c where t.category_id = c.category_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.