运行以下查询时,我试图获取不同的行。但是我得到重复的行 当我使用SELECT DISTINCT时出现错误,并且GROUP BY是相同的,我知道这是可能的,但是我很难弄清楚
不同的记录在第一列TEST.TEST_ID
SELECT TEST.TEST_ID, TEST.TEST_TYP_ID, TEST.LOCATIONSECTIONID, TY.NAME, TEST.TITLE, TXT.TEXT, TEST.REPORT_DATE, TEST.START_DATE, TEST.END_DATE, SC.DISPLAY_NAME, EL.EL_ID, SC.SC_ID, O.DISPLAY_NAME
FROM TEST_TEST AS TEST
LEFT JOIN TEST_TYPE TY ON TEST.TEST_TYP_ID = TY.TEST_TYP_ID
LEFT JOIN TEST_OPTN_TEST OPT ON TEST.TEST_ID = OPT.TEST_ID
LEFT JOIN TEST_OPTN O ON OPT.OPTION_NUMBER = O.OPTION_NUMBER
LEFT JOIN TEST_EL EL ON OPT.EL_ID = EL.EL_ID
LEFT JOIN TEST_TXT TXT ON TEST.TEST_ID = TXT.TEST_ID
LEFT JOIN TEST_EL_SC SC ON OPT.EL_ID = SC.EL_ID
WHERE
TEST.TEST_TYP_ID = 1
AND TEST.TITLE LIKE '%SOME TEXT%'
AND SC.DISPLAY_NAME = 'SOME TEXT'
谢谢
答案 0 :(得分:0)
我知道我收到了错误 无法将ntext数据类型选择为DISTINCT,因为它不可比较。 (第1行) 所以我删除了TXT.TEXT列,得到了不同的行
SELECT DISTINCT TEST.TEST_ID, TEST.TEST_TYP_ID, TEST.LOCATIONSECTIONID, TY.NAME, TEST.TITLE, TEST.REPORT_DATE, TEST.START_DATE, TEST.END_DATE, SC.DISPLAY_NAME, EL.EL_ID, SC.SC_ID, O.DISPLAY_NAME
FROM TEST_TEST AS TEST
LEFT JOIN TEST_TYPE TY ON TEST.TEST_TYP_ID = TY.TEST_TYP_ID
LEFT JOIN TEST_OPTN_TEST OPT ON TEST.TEST_ID = OPT.TEST_ID
LEFT JOIN TEST_OPTN O ON OPT.OPTION_NUMBER = O.OPTION_NUMBER
LEFT JOIN TEST_EL EL ON OPT.EL_ID = EL.EL_ID
LEFT JOIN TEST_TXT TXT ON TEST.TEST_ID = TXT.TEST_ID
LEFT JOIN TEST_EL_SC SC ON OPT.EL_ID = SC.EL_ID
WHERE
TEST.TEST_TYP_ID = 1
AND TEST.TITLE LIKE '%SOME TEXT%'
AND SC.DISPLAY_NAME = 'SOME TEXT'
这可行,但是如果我要包含该文本列,我会这样做。
谢谢