dbTalk Databases Forums  

Need smart sql

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Need smart sql in the comp.databases.postgresql.novice forum.



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

Default Need smart sql - 01-06-2004 , 09:46 AM






Folks,

I'm in need of a little pointer on how to do the following:

I have a company-table and an employee-table. The employee-table has a
company_id field and a birthday-field. Each company-record may relate to no
or some employee records. Nothing too exotic so far, I guess.

Now I want to select all the company-records names and along with the oldest
employee's name. Or, if there is no employee, I want to display something
like 'no employees'.

Anyone?

-> Maximilian Tyrtania | Mty (AT) fischerAppelt (DOT) de
fischerAppelt Kommunikation GmbH
Tucholskystr. 18 | D-10117 Berlin | Germany
Tel. ++49-30-726146-728 | Fax ++49-30-726146-710
www.fischerAppelt.de
--


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #2  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: Need smart sql - 01-06-2004 , 10:49 AM






On Tue, Jan 06, 2004 at 16:46:44 +0100,
Maximilian Tyrtania <Mty (AT) Fischerappelt (DOT) de> wrote:
Quote:
Folks,

I'm in need of a little pointer on how to do the following:

I have a company-table and an employee-table. The employee-table has a
company_id field and a birthday-field. Each company-record may relate to no
or some employee records. Nothing too exotic so far, I guess.

Now I want to select all the company-records names and along with the oldest
employee's name. Or, if there is no employee, I want to display something
like 'no employees'.
One approach would be:

select companyname, coallesce(
(select employeename from employees where employees.company_id =
company.company_id order by birthday limit 1), 'no employees')
from company

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



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.