0
加入的問題我寫了一個查詢,以便從四個不同的表中獲取數據如下:右外mysql中
SELECT crm_countries.country_name as Country,crm_support_inquiry.event_name as Event, crm_inquiry_perticipant.company as Company,crm_inquiry_perticipant.contact_name ContactPerson,crm_inquiry_perticipant.email,
GROUP_CONCAT(CONVERT(Expogroup, CHAR(200)) SEPARATOR '/') AS Expogroup,GROUP_CONCAT(CONVERT(Abdas, CHAR(200)) SEPARATOR '/') AS Abdas, GROUP_CONCAT(CONVERT(AfricaDetails, CHAR(200)) SEPARATOR '/') AS AfricaDetails, GROUP_CONCAT(CONVERT(Kenyadetails, CHAR(200)) SEPARATOR '/') AS Kenyadetails,GROUP_CONCAT(CONVERT(Findexporters, CHAR(200)) SEPARATOR '/') AS Findexporters,GROUP_CONCAT(CONVERT(Dubaiexporters, CHAR(200)) SEPARATOR '/') AS Dubaiexporters,GROUP_CONCAT(CONVERT(IndiaExportNews, CHAR(200)) SEPARATOR '/') AS IndiaExportNews FROM (SELECT inquiry_id,event_id,event_name,CASE WHEN mailer_id = 1 THEN CONCAT(Edition,' - ',sent_on) END AS Expogroup,CASE WHEN mailer_id = 2 THEN CONCAT(Edition,' - ',sent_on) END AS Abdas,CASE WHEN mailer_id = 3 THEN CONCAT(Edition,' - ',sent_on) END AS AfricaDetails,CASE WHEN mailer_id = 4 THEN CONCAT(Edition,' - ',sent_on) END AS Kenyadetails,CASE WHEN mailer_id = 5 THEN CONCAT(Edition,' - ',sent_on) END AS Findexporters, CASE WHEN mailer_id = 6 THEN CONCAT(Edition,' - ',sent_on) END AS Dubaiexporters ,CASE WHEN mailer_id = 7 THEN CONCAT(Edition,' - ',sent_on) END AS IndiaExportNews FROM crm_support_inquiry)
AS crm_support_inquiry, crm_inquiry_perticipant, crm_countries where crm_inquiry_perticipant.inquiry_id=crm_support_inquiry.inquiry_id and crm_countries.country_id=crm_inquiry_perticipant.country GROUP BY crm_support_inquiry.inquiry_id, crm_support_inquiry.event_id,crm_support_inquiry.event_name
這爲它們在crm_perticipant_inquiry和crm_support_inquiry等於IDS的數據。
現在我想要crm_perticipant_inquiry中的所有id的數據,即使這些id的數據在crm_support_inquiry中不存在,它也必須返回null.I使用了正確的外連接並更改了查詢,如下所示,但我沒有得到所需的輸出。 plzz幫助!!
SELECT crm_countries.country_name as Country,crm_support_inquiry.event_name as Event, crm_inquiry_perticipant.company as Company,crm_inquiry_perticipant.contact_name ContactPerson,crm_inquiry_perticipant.email,
GROUP_CONCAT(CONVERT(Expogroup, CHAR(200)) SEPARATOR '/') AS Expogroup,GROUP_CONCAT(CONVERT(Abdas, CHAR(200)) SEPARATOR '/') AS Abdas, GROUP_CONCAT(CONVERT(AfricaDetails, CHAR(200)) SEPARATOR '/') AS AfricaDetails, GROUP_CONCAT(CONVERT(Kenyadetails, CHAR(200)) SEPARATOR '/') AS Kenyadetails,GROUP_CONCAT(CONVERT(Findexporters, CHAR(200)) SEPARATOR '/') AS Findexporters,GROUP_CONCAT(CONVERT(Dubaiexporters, CHAR(200)) SEPARATOR '/') AS Dubaiexporters,GROUP_CONCAT(CONVERT(IndiaExportNews, CHAR(200)) SEPARATOR '/') AS IndiaExportNews FROM
(SELECT inquiry_id,event_id,event_name,CASE WHEN mailer_id = 1 THEN CONCAT(Edition,' - ',sent_on) END AS Expogroup,CASE WHEN mailer_id = 2 THEN CONCAT(Edition,' - ',sent_on) END AS Abdas,CASE WHEN mailer_id = 3 THEN CONCAT(Edition,' - ',sent_on) END AS AfricaDetails,CASE WHEN mailer_id = 4 THEN CONCAT(Edition,' - ',sent_on) END AS Kenyadetails,CASE WHEN mailer_id = 5 THEN CONCAT(Edition,' - ',sent_on) END AS Findexporters, CASE WHEN mailer_id = 6 THEN CONCAT(Edition,' - ',sent_on) END AS Dubaiexporters ,CASE WHEN mailer_id = 7 THEN CONCAT(Edition,' - ',sent_on) END AS IndiaExportNews FROM crm_support_inquiry)
AS crm_support_inquiry right outer join crm_inquiry_perticipant on crm_inquiry_perticipant.inquiry_id=crm_support_inquiry.inquiry_id, crm_countries where crm_countries.country_id=crm_inquiry_perticipant.country GROUP BY crm_support_inquiry.inquiry_id, crm_support_inquiry.event_id,crm_support_inquiry.event_name
我得到和以前一樣的輸出。沒有變化 – user3300727 2015-01-21 10:58:47
只有一行額外。但是有成千上萬的IDS。 – user3300727 2015-01-21 11:00:39