tags:

views:

59

answers:

4

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
+4  A: 

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.

LesterDove
Or maybe this should have been a comment, given the posts above. Learning...
LesterDove
Mixture of both Lester -- you're probably right about the alias but the questions should be comments.
Austin Salonen
+1  A: 
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
Glennular
+1  A: 

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
eKek0
+1  A: 

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
OMG Ponies
+1 interesting - didn't know you could create dotted aliases for columns... you learn something *every* day ! :-)
marc_s
@marc_s: Did it with backticks in MySQL recently, but I certainly don't recommend the practice. I'd buy the following for any co-irkers who do: http://www.despair.com/mis24x30prin.html
OMG Ponies