连接两个mysql表 [英] Join two mysql tables
问题描述
我有两个数据库-一个用于文章,另一个用于文章的元信息(例如作者,日期,类别和抄本).我在元表中有以下几列:ID,商品ID,元类型和元值.我想知道如何通过一个mysql查询将这两个表结合在一起以获取文章和元信息.文章ID在元表中不是唯一的,这就是为什么我无法弄清楚如何访问文章的特定元类型和相应值的原因.
I have two databases - one for articles and the another for the articles' meta information (Like author, date, category and atc.). I have the following columns in meta table: ID, article id, meta type and meta value. I wonder how can I join these two tables to get both - article and meta information - with one mysql query. The article id isn't unique in meta table, that is why I can't figure out how to access specific meta type and according value for the article.
推荐答案
SELECT *
FROM article_table
RIGHT JOIN meta_table
ON article_table.article_id = meta_table.article_id;
SELECT *
FROM article_table
RIGHT JOIN meta_table
ON article_table.article_id = meta_table.article_id;
您可以从商品表中获得重复信息,但是它会在单个查询中获取所有元数据.我相信否则您需要使用多个.
You get repeats from the article table, but it gets all the meta data in a single query. I believe otherwise you need to use multiple.
这篇关于连接两个mysql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!