我有两个表格; productstorymap
和stories
。 productstorymap
有productId
和storyId
列。 stories
有id
和status
列。在MySQL中同时查询两个表格
我需要查询属于某个产品并具有一定状态的所有故事。我得最近的是
SELECT map.*, story.*
FROM productstorymap map, stories story
WHERE map.productId=1 AND story.status=1
但它返回我不属于产品1,它返回像这样的故事:
Array
(
[0] => Array
(
[id] => 1
[productId] => 1
[storyId] => 1
[name] => Create a User Story
[content] => Admin should be able to create user stories.
[duration] => 1
[priority] => 0
[created] => 2010-09-22 17:36:21
[edited] =>
[status] => 1
)
[1] => Array
(
[id] => 4
[productId] => 1
[storyId] => 1
[name] => Bar
[content] => Xyzzy!
[duration] =>
[priority] => 1
[created] => 2011-02-10 17:50:56
[edited] => 2011-02-10 17:50:56
[status] => 1
)
)
即使productstorymap只有两行:
ID prodcutId storyID
1 1 1
2 7 4
我正在使用MySQL和PHP,如果这是相关的。
我得到它的第一个解决方案。谢谢! – Harri 2011-02-10 17:24:52