1
我有一個表simsu_subs,它具有字段user_id和過期日期。 相同的字段名稱user_id在另一個表mt_links中使用。將表添加到現有查詢
我有這樣的查詢工作完美:
SELECT link_published,
CASE link_published WHEN 1 THEN 'Published' ELSE 'No' END AS 'Published/no',
u.firstname,
u.lastname,
accreditations,
title_descriptor,
phone_number,
display_email,
u.website,
avatar,
logo,
disclaimer,
signature_ie_john_doe,
MAX(IF(lv.cf_id =24, lv.`value`, '')) AS `UploadGraphic`,
MAX(IF(lv.cf_id =36, lv.`value`, '')) AS `Color`,
MAX(IF(lv.cf_id =37, lv.`value`, '')) AS `BodyCopy`,
MAX(IF(lv.cf_id =39, lv.`value`, '')) AS `Salutation`,
l.link_name,
MAX(IF(lv.cf_id =38, lv.`value`, '')) AS `Magazine`,
address,
MAX(IF(lv.cf_id =35, lv.`value`, '')) AS `Address 2`,
city,
state,
postcode FROM cwpc_jsn_users u
INNER JOIN cwpc_mt_links l ON u.`id` = l.`user_id`
INNER JOIN cwpc_mt_cfvalues lv ON l.link_id = lv.link_id
GROUP BY u.firstname, l.link_name
這是我想添加查詢:
SELECT b.expiry_date
FROM cwpc_simsu_subs b
JOIN cwpc_mt_links c
ON b.user_id = c.user_id
我想EXPIRY_DATE添加到該查詢,通過USER_ID加入。我試圖以更多的方式將字段和內部聯接別名,而不是我所關心的。我只是無法讓它工作。我在想
INNER JOIN cwpc_mt_links l ON u。
id
= 1。user_id
與它有什麼關係?不完全確定。
有人能指出我正確的方向嗎?
THX
我沒想到要重用u.id而不是給它另一個別名。愚蠢的錯誤,真的。感謝您指出這一點! –