【发布时间】:2011-11-12 19:44:45
【问题描述】:
可能重复:
SQL - how to SELECT multiple tables and JOIN multiple rows from the same column?
我有三个 MySQL 表 - language、category 和 property
/*
table `language`
`WHERE language.url='link'`*/
id | url
-----+-----
111 | link
/*
table `category`
`SELECT category.id, category.order`*/
id | order | group | type | location
-----+--------+-------+------+---------
111 | 3 | a42 | a81 | a63
/*
table `property`
`LEFT JOIN properties ON properties.id = category.group`*/
id | status
----+-------
a42 | public
a81 | update
a63 | states
和 SQL
SELECT category.id, category.order, language.url, property.status AS `group`
FROM category
LEFT JOIN language
USING ( id )
LEFT JOIN property ON property.id = category.group
WHERE language.url='link'
LIMIT 1
返回
id | order | url | group
----+-------+-------+-------
111 | 3 | link | public
SQL:如何从表property 中再返回两行数据,结果将是:
id | order | url | group | type | location
----+-------+-------+--------+--------+---------
111 | 3 | link | public | update | states
【问题讨论】:
-
你应该真正编辑你现有的问题,而不是问另一个问题,或者删除一个。
-
没关系,但您可能无法获得所需的选票。如果您标记问题并在文本框中说明您打开了两个问题并想关闭它,版主可以这样做。