Alteryx Designer

Find answers, ask questions, and share expertise about Alteryx Designer.

sql query help

Highlighted
6 - Meteoroid

Hello,

I have a query and I may get up to 3 different records returned with 3 different dates. Is there a way I can limit my results to 1 record with the latest date? Thank you for any help you can provide.

Jim

Highlighted
Alteryx
Alteryx

hi @jhouseslu,

 

you can always limit the amount of records within the workflow. Add a sort tool with the date on descending order and a sample tool contains the first 1st row.

 

VianneyM_0-1582645204876.png

 

 

Let me know if that works for you

 

Best,

Vianney

Best,
Vianney
Highlighted
Alteryx Certified Partner
Alteryx Certified Partner

Hi @jhouseslu, you could use @VianneyM's approach to do the filtering/sampling in Alteryx, or maybe attempt to do so in the source SQL itself. Something like:

 

SELECT
DATE_COLUMN,DIMENSION1,DIMENSION2
FROM TABLE_NAME
WHERE

DATE = (SELECT MAX(DATE) FROM TABLE_NAME)

 

Highlighted
Alteryx Certified Partner
Alteryx Certified Partner

Hi @jhouseslu ,

 

if you are looking for a solution using only SQL, you could try:

 

SELECT *
FROM MyTable AS a
JOIN
(SELECT IdColumn, MAX(Date) AS MaxDate
FROM MyTable
GROUP BY IdColumn) AS b
ON
a.Date = b.MaxDate
AND
a.IdColumn = b.IdColumn

 

Best,

 

Roland

Labels