Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: SQL queries confusion  (Read 110 times)

MadsPH

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

Hi!

I'm not very strong around SQL, so this statement confuses me.
Code: [Select]
$query_articles = 'SELECT
a.id AS aid,title,a.seftitle AS asef,text,a.date,
a.displaytitle,a.displayinfo,a.commentable,a.visible
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?
Logged

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.'
Logged

nukpana

  • 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
Logged