我有四个桌子。
BHD 选择 FTB DRM
我想从BHD获得列代理和状态,从OPT获得描述,从FTB获得booking_actual零售,从DRM获得analysis_master1。
BHD中的full_reference列链接到FTB.Reference,DRM.code链接到BHD.AGENT,OPT_ID链接到BHD_ID。
我尝试过:
DELETE FROM e78_posts WHERE id IN (SELECT a.post_id FROM ( SELECT MIN(meta_id) AS `meta_id` ,MIN(post_id) AS `post_id` FROM e78_postmeta WHERE meta_key='_sku' GROUP BY meta_value HAVING COUNT(*) > 1 ) a )
DELETE FROM e78_postmeta WHERE meta_id IN (SELECT a.meta_id FROM ( SELECT MIN(meta_id) AS `meta_id` ,MIN(post_id) AS `post_id` FROM e78_postmeta WHERE meta_key='_sku' GROUP BY meta_value HAVING COUNT(*) > 1 ) a )
并得到:
在FROM子句中多次指定了相关名称'bad'。
只是想知道我要去哪里错了,或者有人是否有更好的主意?
答案 0 :(得分:0)
这应该有效
SELECT bad.agent as agents,
bad.status as thestatus,
desc.description as product,
retail.booking_actual_retail as actualretail,
country.analysis_master1 as countries
from BHD bad
inner join FTB on ftb.booking_reference = bad.FULL_REFERENCE
inner join DRM Country on bad.agent = country.code
inner join OPT desc on bad.id = desc.id
答案 1 :(得分:0)
SELECT bad.agent as Agents,
bad.status as TheStatus,
desc1.description as Product,
country.analysis_master1 as Country,
ftb.booking_actual_retail as ActualRetail,
ftb.Entered_Date
from BHD bad
inner join FTB on ftb.booking_reference = bad.FULL_REFERENCE
inner join DRM Country on bad.agent = country.code
inner join OPT desc1 on bad.BHD_ID = desc1.OPT_ID