Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM SQL » View Thread |
Messages 1 to 10 of 12 total |
Selecting single individuals |
Tue, Aug 7 2007 4:14 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | The sql below is selecting individuals from a career table. At present I get one entry for each occurrence of an individual (ie if someone has been promoted there will be two entries). The rules for the database are that if someone leaves the company or is promoted then the date _Left is set.
What I want to achieve (preferably in a single statement - ie no scripts) is only one entry for each individual, and where there are multiple entries in the underlying table all I want is the one without an _Left date, or where they all have _Left dates, the most recent. SELECT _ID, _Forename +' '+_Surname AS _Name, W._JobTitle, W._Left, IF(W._Left IS NULL THEN TRUE ELSE FALSE) AS _StillThere, W._fkSites, _Surname+', '+_Forename AS _SortName FROM Contacts JOIN Career W ON W._fkContacts = _ID WHERE W._fkCompanies = :CompanyID Roy Lambert |
Wed, Aug 8 2007 3:40 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Roy,
<< What I want to achieve (preferably in a single statement - ie no scripts) is only one entry for each individual, and where there are multiple entries in the underlying table all I want is the one without an _Left date, or where they all have _Left dates, the most recent. >> Try this: SELECT _ID, _Forename +' '+_Surname AS _Name, MAX(W._Left) as Left, W._JobTitle, IF(MAX(W._Left) IS NULL THEN TRUE ELSE FALSE) AS _StillThere, W._fkSites, _Surname+', '+_Forename AS _SortName FROM Contacts JOIN Career W ON W._fkContacts = _ID WHERE W._fkCompanies = :CompanyID GROUP BY 1, 2, 4, 6, 7; -- Tim Young Elevate Software www.elevatesoft.com |
Thu, Aug 9 2007 3:28 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
Thanks but no prize, still get multiple entries for an individual But what is > GROUP BY 1, 2, 4, 6, 7; The result set is used to populate a couple of grids - current employees and ex-employees so what I've done is order it by date left so the current staff are at the top and then whilst looping stuff the id into a sorted stringlist, if its already there don't put into the grid - it works and is reasonably fast. Roy Lambert |
Thu, Aug 9 2007 2:48 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Roy,
<< Thanks but no prize, still get multiple entries for an individual >> Sorry, it's very hard to give an answer to these types of questions without metadata and some understanding of what the tables look like in terms of the rows and uniqueness of the various columns. << But what is GROUP BY 1, 2, 4, 6, 7; >> It's the way DBISAM allows you to use ordinal SELECT column positions in ORDER BY or GROUP BY clauses. -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Aug 10 2007 4:10 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
>Sorry, it's very hard to give an answer to these types of questions without >metadata and some understanding of what the tables look like in terms of the >rows and uniqueness of the various columns. I know and you do very good job most of the time Roy Lambert |
Fri, Aug 10 2007 5:35 AM | Permanent Link |
Chris Erdal | Roy Lambert <roy.lambert@skynet.co.uk> wrote in
news:F457E6D7-A972-4865-8C5E-A36DBC863699@news.elevatesoft.com: > Thanks but no prize, still get multiple entries for an individual > > But what is > >> GROUP BY 1, 2, 4, 6, 7; > > The result set is used to populate a couple of grids - current > employees and ex-employees so what I've done is order it by date left > so the current staff are at the top and then whilst looping stuff the > id into a sorted stringlist, if its already there don't put into the > grid - it works and is reasonably fast. > > Roy Lambert Roy, What about Tim's SQL with GROUP BY 1 ORDER BY 1, 2 IIUC this won't work in EDB but it might in DBISAM -- Chris (XP-Pro + Delphi 7 Architect + DBISAM 4.25 build 4 + EDB 1.04 build 3) |
Fri, Aug 10 2007 12:13 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Roy,
<< I know and you do very good job most of the time >> Not really, but thanks for saying so anyways. I'm better at the internals than I am at actually using the SQL. -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Aug 10 2007 1:42 PM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
Yeah but at least you understand the gibberish - for me its still a foreign tounge - generally spoken after to much ale Roy Lambert |
Mon, Aug 13 2007 4:02 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Roy,
<< Yeah but at least you understand the gibberish - for me its still a foreign tounge - generally spoken after to much ale >> It's actually quite nice when you start using it a bit more, and it translates to a lot of different development environments, etc. -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Aug 17 2007 1:22 PM | Permanent Link |
John | Why don't you select into a memory table, and then select distinct from the memory table?
Just a thought from a novice... Roy Lambert <roy.lambert@skynet.co.uk> wrote: The sql below is selecting individuals from a career table. At present I get one entry for each occurrence of an individual (ie if someone has been promoted there will be two entries). The rules for the database are that if someone leaves the company or is promoted then the date _Left is set. What I want to achieve (preferably in a single statement - ie no scripts) is only one entry for each individual, and where there are multiple entries in the underlying table all I want is the one without an _Left date, or where they all have _Left dates, the most recent. SELECT _ID, _Forename +' '+_Surname AS _Name, W._JobTitle, W._Left, IF(W._Left IS NULL THEN TRUE ELSE FALSE) AS _StillThere, W._fkSites, _Surname+', '+_Forename AS _SortName FROM Contacts JOIN Career W ON W._fkContacts = _ID WHERE W._fkCompanies = :CompanyID Roy Lambert |
Page 1 of 2 | Next Page » | |
Jump to Page: 1 2 |
This web page was last updated on Monday, May 6, 2024 at 03:23 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |