0

如何向连接行添加其他信息?

SELECT column1, column2
FROM table1
LEFT JOIN table2 
    ON column1 = col1_table2 //The row which matches with this join should have additional information e.g. "'joined' AS info

非常感谢你的帮助!

4

2 回答 2

2

如果我理解你的问题,这应该有效:

SELECT 
    t1.column1, 
    t1.column2, 
    CASE WHEN t2.col1_table2 IS NOT NULL THEN 'joined' END AS info
FROM table1 t1
LEFT JOIN table2 t2 ON t1.column1 = t2.col1_table2 
于 2012-04-06T16:08:53.687 回答
2

尝试这个:

SELECT column1, 
       column2,  
       CASE WHEN col1_table2 IS NOT NULL THEN 'joined' END AS additional_field 
FROM table1
LEFT JOIN table2 ON column1 = col1_table2 
于 2012-04-06T16:09:31.427 回答