Query Re listing Text column associated with number column

Creating tables and queries
Post Reply
StormWolf
Posts: 12
Joined: Sun Jul 08, 2018 12:46 pm

Query Re listing Text column associated with number column

Post by StormWolf »

Hi All,

I have a query question. I can list the first and last number in a series using Min and Max, no probs, but my problem is to also list the associated text with the number. My setup is TableID, Series, Details. Running Min or Max with text gives the wrong result.

Thanks
Open Office 4.1.3 Using Windows 10
chrisb
Posts: 298
Joined: Mon Jun 07, 2010 4:16 pm

Re: Query Re listing Text column associated with number colu

Post by chrisb »

a self join is probably the most efficient solution.
replace the two instances of 'MyTable' with the name of your table:

Code: Select all

select t2.*
from
	(select min("Series") mn, max("Series") mx from "MyTable") t1
join
	(select "TableID", "Series", "Details" from "MyTable") t2
	on t1.mn = t2."Series" or t1.mx = t2."Series"
open office 4.1.14 & LibreOffice 6.4.4.2 x64 using HSQL 1.8.0.10 (Embedded) and HSQL 2.6.0 (Split) on Windows 10
Post Reply