Zen Cart Logo
Forums / General Questions / Why SQL query have p, pd etc on Zen Cart but table in SQL no the p or pd?

Why SQL query have p, pd etc on Zen Cart but table in SQL no the p or pd?

Views: 1,438

Results 1 to 3 of 3
14 Aug 2011, 1:39 PM
#1
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Why SQL query have p, pd etc on Zen Cart but table in SQL no the p or pd?

Hi all,

I am new on php/MySQL and now want to learning it to take more control of Zen Cart.

I have one questions not understand.

It is on MySQL table, such as products, inside it haven't the "p", for example products_id, products_model etc.

But general on the php coding, will see like that query

$products_query_raw = "select p.products_id, p.products_model, pd.products_name, p.products_quantity, p.products_type from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id='" . $_SESSION['languages_id'] . "' order by ".$sOrder." ";
$products = $db->Execute($products_query_raw);

Why add the addition p or pd. on the table's column name on the query? What do it doing?

Thank you very much. And anyone can give me a tutorial good for beginner like me?

14 Aug 2011, 1:46 PM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Why SQL query have p, pd etc on Zen Cart but table in SQL no the p or pd?

It's called an alias and is a short way of talking to mysql about the table without having to type the whole table name each time.

Otherwise we would have to say things like products.products_id = products_description.products_id when using more than one table in a query to tell mysql to which we are referring, which would get a bit tedious.

There's a tutorial on it here.

15 Aug 2011, 3:58 AM
#3
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Re: Why SQL query have p, pd etc on Zen Cart but table in SQL no the p or pd?

Kurio,

Thank you very much, now understand where the p, po come from by SQL Alias. :clap: