dbTalk Databases Forums  

fully qualified table names - not just for querying?

comp.databases comp.databases


Discuss fully qualified table names - not just for querying? in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
metaperl
 
Posts: n/a

Default fully qualified table names - not just for querying? - 02-17-2009 , 01:26 PM






I think this bug <http://bugs.mysql.com/bug.php?id=27262> sums up my
quandry perfectly:

<BLOCKQUOTE>
It makes no sense that I can use fully qualified names in the query,
but results can not
be returned fully qualified as well.
</BLOCKQUOTE>

I have a situation where I need to select from the same table twice -
I need to get the work and fax phone numbers for a person.

Now I can use table aliases to make each query of the phone table
distinct (one such call shown:

SELECT *
FROM agents
INNER JOIN people ON ( people.id = agents.people_id )
INNER JOIN phone AS work_phone ON ( work_phone.people_id = people.id
AND work_phone.phone_type = (
SELECT id
FROM phone_types
WHERE enum_name = 'Work' ) )

but there is no way to get back the results with the column names
table-qualified.

So I am going to be forced to make the queries for phone one at a time
because there will be a column name conflict when I use the same table
to get the fax phone in addition to the work phone...




Reply With Quote
  #2  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: fully qualified table names - not just for querying? - 02-17-2009 , 01:40 PM






metaperl wrote on 17.02.2009 20:26:
Quote:
SELECT *
FROM agents
INNER JOIN people ON ( people.id = agents.people_id )
INNER JOIN phone AS work_phone ON ( work_phone.people_id = people.id
AND work_phone.phone_type = (
SELECT id
FROM phone_types
WHERE enum_name = 'Work' ) )

but there is no way to get back the results with the column names
table-qualified.

So I am going to be forced to make the queries for phone one at a time
because there will be a column name conflict when I use the same table
to get the fax phone in addition to the work phone...
No you are not, stop using SELECT * and give each column an alias

SELECT work_phone.phone_number as work_phone,
home_phone.phone_number as home_phone
FROM agents
INNER JOIN people ON ( people.id = agents.people_id )
INNER JOIN phone AS work_phone ON ( work_phone.people_id = people.id AND
work_phone.phone_type = 1)
INNER JOIN phone AS home_phone ON ( home_phone.people_id = people.id AND
work_phone.phone_type = 2)

(I simplified the condition on the phone_type)

Thomas


Reply With Quote
  #3  
Old   
Jasen Betts
 
Posts: n/a

Default Re: fully qualified table names - not just for querying? - 02-18-2009 , 06:06 AM



On 2009-02-17, metaperl <metaperl (AT) gmail (DOT) com> wrote:
Quote:
I think this bug <http://bugs.mysql.com/bug.php?id=27262> sums up my
quandry perfectly:

BLOCKQUOTE
It makes no sense that I can use fully qualified names in the query,
but results can not
be returned fully qualified as well.
/BLOCKQUOTE

select foo.bar as "foo.bar" from foo;

the above works in postgres 8.3, and may work in other systems too.

Quote:
I have a situation where I need to select from the same table twice -
I need to get the work and fax phone numbers for a person.

Now I can use table aliases to make each query of the phone table
distinct (one such call shown:
you just need column aliases... which means not using select * but
naming (and aliasing where apropriate) the columns that interest you.




Reply With Quote
  #4  
Old   
metaperl
 
Posts: n/a

Default Re: fully qualified table names - not just for querying? - 02-18-2009 , 09:07 AM



On Feb 17, 2:40*pm, Thomas Kellerer <FJIFALSDG... (AT) spammotel (DOT) com>
wrote:

spammotel - lol

Quote:
No you are not, stop using SELECT * and give each column an alias
yes, using VIEWS makes this process much simpler.

amazing what a night's sleep will do for you.


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.