Only display the highest alpha in loop

Airikr

I want to only display the highest value of them all, within a foreach loop. The following query is inside this foreach loop.

SELECT MAX(substring_index(data_column, ' ', -1))
FROM table
WHERE id = '{id-from-the-loop}'
AND data_column != ''

The query gives me this result:

Data A
Data A
Data C
Data B
Data G
Data E

G is the highest value in the list above, so it will show like the list below, but I can't figure it out!

Data
Data
Data
Data
Data G
Data

How can I solve this?

D-Shih

You can try this, write a subquery to get highest value of them all by limit 1 and order by

then self outer join with coalesce function.

CREATE TABLE T(col varchar(50));

INSERT INTO T VALUES ('Data A');
INSERT INTO T VALUES ('Data A');
INSERT INTO T VALUES ('Data C');
INSERT INTO T VALUES ('Data B');
INSERT INTO T VALUES ('Data G');
INSERT INTO T VALUES ('Data E');

Query 1:

SELECT coalesce(t2.col,substring_index(t1.col, ' ', 1)) col
FROM T t1 LEFT JOIN (
   select col 
   from t
   order by col desc 
   limit 1
) t2 on t1.col =t2.col

Results:

|    col |
|--------|
| Data G |
|   Data |
|   Data |
|   Data |
|   Data |
|   Data |

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From records display only the one with highest price

Using for loop, how do I get the highest mark and display in python?

Material UI - Slider: Display only the lowest and the highest markLabel

How to display only value that occurs second highest number of times?

How to display multiple items but only the highest values in year and month for each?

Display the category name in wordpress loop only once

Wordpress: Display only category name within The Loop

Display only last result in fum of series in for loop

Rsync files based on highest alpha within a date

SQL : For each ID, only display the highest value from another column (can't group by)

How to display only the highest "score" according to the text content inside each div?

Can I display the second highest only (or 3rd.. so on) value using usort function?

Display value with highest number in Shiny

How to display Softmax highest probability

Display The Corresponding Cells Of The Highest Amounts

How to display the highest value in an array

How to display highest and lowest of an array

Display highest value in array in C

How to display div only once in the loop and next div display inside div which run only once

Sorting foreach loop by highest number

Bash nested loop get highest

Melt only highest values in matrix

How to display a block of code at the end of a foreach loop only once

Display distinct values only, if size is not equal to desired length return to loop

Vue loop using v-for then display only if no condition met

How to loop through javascript array and display only part of array then repeat

C# For Loop How to Display Only Matching Values

Using regex to parse through loop to display only matching results?

How to display only the end result in a while loop PHP?