Page 1 of 1

I have never seen this before.

Posted: Fri Jun 18, 2010 6:17 am
by Steji
"SELECT ph.*, p.price, s.width as widthin, s.height as heightin, m.name as material, d.width as frame_width, d.depth as frame_depth FROM photograph"

Just an example of what I'm looking at, what I don't understand is the prefixed table columns. It must be for other tables in the database as none of these columns are in the table photograph so why have FROM photograph in the query? Also there is more than one table beginning with 's' so how is s.height found when it could be in one of two tables?

Thanks

Re: I have never seen this before.

Posted: Fri Jun 18, 2010 8:24 am
by Benjamin
It appears the rest of the query is missing. Those are simply aliases.

Code: Select all

select ph.* from some_table ph where ph.foo = 'bar'
That assigns ph as an alias of some_table.

Re: I have never seen this before.

Posted: Fri Jun 18, 2010 10:26 am
by Steji

Code: Select all

"SELECT ph.*, p.price, s.width as widthin, s.height as heightin, m.name as material, d.width as frame_width, d.depth as frame_depth FROM photograph ph, poster_print_prices p, sizes s, frames f, material m, dimensions d WHERE (ph.session_id='$sessionid' or (ph.user_id = '$userid' and ph.user_id > 0)) and ph.order_id='0' and p.id = ph.price_id and m.id = f.material_id and f.dimensions_id = d.id";
I can't see where the other aliases are defined like d or s?

Re: I have never seen this before.

Posted: Fri Jun 18, 2010 10:30 am
by AbraCadaver
Steji wrote:

Code: Select all

"SELECT ph.*, p.price, s.width as widthin, s.height as heightin, m.name as material, d.width as frame_width, d.depth as frame_depth FROM photograph ph, poster_print_prices p, sizes s, frames f, material m, dimensions d WHERE (ph.session_id='$sessionid' or (ph.user_id = '$userid' and ph.user_id > 0)) and ph.order_id='0' and p.id = ph.price_id and m.id = f.material_id and f.dimensions_id = d.id";
I can't see where the other aliases are defined like d or s?
Look harder:

FROM photograph ph, poster_print_prices p, sizes s, frames f, material m, dimensions d

Re: I have never seen this before.

Posted: Fri Jun 18, 2010 10:43 am
by Steji
Thanks, I honestly don't know why I couldn't see that!