SQL内连接问题

时间:2010-05-17 20:59:43

标签: sql inner-join

以下SQL查询无效。我认为错误发生在第一行。

SELECT 
    SUBSTRING(tbl_news.comment, 1, 250) as tbl_news.comment, 
    tbl_news.id, tbl_news.date, tbl_news.subject, tbl_users.username 
FROM 
     tbl_news
INNER JOIN 
     tbl_users ON tbl_news.creator = tbl_users.id
ORDER BY 
     date DESC

4 个答案:

答案 0 :(得分:4)

我认为您的别名as tbl_news.comment不允许包含点。你遇到了什么错误?它有什么样的SQL风格?感谢。

答案 1 :(得分:1)

SELECT SUBSTRING(tbl_news.comment, 1, 250) as comment, 
        tbl_news.id, tbl_news.date, tbl_news.subject, tbl_users.username FROM tbl_news
        INNER JOIN tbl_users ON tbl_news.creator = tbl_users.id
        ORDER BY date DESC

答案 2 :(得分:1)

试试这个:

SELECT SUBSTRING(tbl_news.comment, 1, 250) as comment, 
        tbl_news.id, tbl_news.date, tbl_news.subject, tbl_users.username 
FROM tbl_news
INNER JOIN tbl_users ON tbl_news.creator = tbl_users.id
ORDER BY date DESC

答案 3 :(得分:1)

使用:

  SELECT SUBSTRING(tn.comment, 1, 250) AS "tbl_news.comment", 
         tn.id, 
         tn.date, 
         tn.subject, 
         tu.username 
    FROM tbl_news tn
    JOIN tbl_users tu ON tu.id = tn.creator
ORDER BY tn.date DESC

在列别名上使用单引号在SQL Server上也适用于我:

  SELECT SUBSTRING(tn.comment, 1, 250) AS 'tbl_news.comment', 
         tn.id, 
         tn.date, 
         tn.subject, 
         tu.username 
    FROM tbl_news tn
    JOIN tbl_users tu ON tu.id = tn.creator
ORDER BY tn.date DESC