sark9012
sark9012

Reputation: 5717

SQL inner join problem

The following SQL query isn't working. I think the error is on the first line.

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

Upvotes: 0

Views: 884

Answers (4)

OMG Ponies
OMG Ponies

Reputation: 332521

Use:

  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

Using single quotes on the column alias also worked for me on 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

Upvotes: 1

eKek0
eKek0

Reputation: 23289

Try this:

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

Upvotes: 1

Glennular
Glennular

Reputation: 18215

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

Upvotes: 1

LesterDove
LesterDove

Reputation: 3044

I don't think your alias as tbl_news.comment is allowed to have a dot in it. What error are you getting? What flavor of SQL is it? Thanks.

Upvotes: 4

Related Questions