Please login or register.

Login with username, password and session length
Advanced search  


You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: SQL queries confusion  (Read 2289 times)


  • Newbie
  • *
  • Karma: 0
  • Posts: 6
SQL queries confusion
« on: February 20, 2013, 02:21:26 pm »


I'm not very strong around SQL, so this statement confuses me.
Code: [Select]
$query_articles = 'SELECT AS aid,title,a.seftitle AS asef,text,,
FROM '._PRE.'articles'.' AS a
WHERE position = 1
AND a.published =1
AND category = '.$_catID.$visible.'
ORDER BY artorder ASC,date DESC
LIMIT '.($currentPage - 1) * $article_limit.','.$article_limit;

I get the whole thing, except for one little thing. Why does the text column not have the prefix a.? It IS located in '_PRE.'articles'.', so why does it (as the only one) not have that a. specified?

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: SQL queries confusion
« Reply #1 on: February 20, 2013, 06:20:27 pm »

Hi Mads,
Welcome to sNews! Hope you'll enjoy it.

Your question: why doesn't 'text' have the prefix 'a.'? Simple. Yes, it IS located in _PRE.'articles', but it is ONLY located in the articles table. Things like title, sef, id, position etc on the other hand are found in other tables as well. At least, I think this is the rationale, I don't really know. After all, there are other bits that also are only found in the articles table but DO have the prefix 'a.' which can be seen as inconsistent.

Anyway, short answer: text is only found in the table articles, so it doesn't need prefix 'a.'


  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: SQL queries confusion
« Reply #2 on: February 21, 2013, 11:22:25 am »

Shorter answer. Since I don't know where in the file this is from, it may be part of a larger query (SQL or php if), hence a need for the alias.

By itself, it doesn't need alias