我有这些表:
table : _newapp_shop_products_events
+-------+-----------+-----------+-------------------+
| EventID | categoryID | Price |
+-------+-----------+-----------+-------------------+
| 9050 | 1 | 15.00 |
| 5048 | 2 | 12.00 |
+-------+-----------+-----------+-------------------+
table : _newapp_shop_products_categories
+-------+-----------+-----------+-------------------+
| CategoryID | Category_Name | photo |
+-------+-----------+-----------+-------------------+
| 1 | Tickets | one.jpg |
| 2 | Voucher | two.jpg |
+-------+-----------+-----------+-------------------+
table : _newapp_shop_products_activitys
+-------+-----------+-----------+-------------------+
| ActivityID | categoryID | Price |
+-------+-----------+-----------+-------------------+
| 80 | 1 | 13.00 |
| 95 | 2 | 18.00 |
+-------+-----------+-----------+-------------------+
这些是通过关系,类别->事件,类别->活动链接的。
我想在一个列表中显示事件和活动(“事件和活动表”而不是_newapp的事件),并且仅显示categoryID = 1的两个表中的项目。我该如何解决?
我试图加入它们或将它们全部选择为一个联合,它返回的行很好,但mysql中的内部链接已损坏。当我单击“活动”的第二个结果集时,id是正确的且价格正确,但是当我单击ID转到相应的ID时,它会生成0行结果,因为它会生成查询:SELECT * FROM representin_nl_-_1.Events WHERE Id = 5
但是错误的表格,应改为在SELECT * FROM representin_nl_-_1._newapp_shop_products_activitys WHERE Id = 5
中搜索。结果:当我单击它的第一个9050时,它将转到正确的行,但其后的ID为not found
。结果:
答案 0 :(得分:2)
您可能想要一个UNION
SELECT 'Event' AS Type, EventID AS Id, Price
FROM Events
WHERE CategoryId = 1
UNION ALL
SELECT 'Activity' AS Type, ActivityID AS Id, Price
FROM Activity
WHERE CategoryId = 1
您是什么意思ID冲突?您可以改成这样
SELECT EventID, null AS ActivityId, Price
FROM Events
WHERE CategoryId = 1
UNION ALL
SELECT null, ActivityID, Price
FROM Activity
WHERE CategoryId = 1