Unix Technical Forum

Alias with a Join

This is a discussion on Alias with a Join within the MySQL forums, part of the Database Server Software category; --> Here's the basic statement: SELECT * FROM `log` LEFT JOIN (`ticket`, `responder`) ON `log`.`ticket_id` = `ticket`.`id` AND `log`.`responder_id` = ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:30 AM
ashore
 
Posts: n/a
Default Alias with a Join

Here's the basic statement:
SELECT * FROM `log` LEFT JOIN (`ticket`, `responder`) ON
`log`.`ticket_id` = `ticket`.`id` AND `log`.`responder_id` =
`responder`.`id`;

That works.

Now I'd like to alias a number of fields in the 'joined' tables,
ticket and responder. How do I express an alias of, say, ticket.name
or responder.status?

Thanks, all.

-AS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:30 AM
lark
 
Posts: n/a
Default Re: Alias with a Join

== Quote from ashore (shoreas@gmail.com)'s article
> Here's the basic statement:
> SELECT * FROM `log` LEFT JOIN (`ticket`, `responder`) ON
> `log`.`ticket_id` = `ticket`.`id` AND `log`.`responder_id` =
> `responder`.`id`;
> That works.
> Now I'd like to alias a number of fields in the 'joined' tables,
> ticket and responder. How do I express an alias of, say, ticket.name
> or responder.status?
> Thanks, all.
> -AS


the alias would be on the table. your statement would look like this:
select *
from log a
left join (ticket b, responder c) on
a.ticket_id = b.id
and a.responder_id = c.id

you see how it is cleaner and shorter.
--
POST BY: lark with PHP News Reader ;o)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 10:30 AM
ashore
 
Posts: n/a
Default Re: Alias with a Join

Yes, but ... .

How do I express a fieldname alias, not a tablename. (E.g., b.name or
c.status) ?

thanks again.

AS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 10:30 AM
ashore
 
Posts: n/a
Default Re: Alias with a Join

Hey, I played with it and got it. I didn'tr realize MySQL was smart
enough to sort-of backtrack in the parsing process. Thanks.

-AS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:13 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com