-1

So I have a database that has some values like this:

Level , Indicator

4       1
3       2
4       3
3       4
4       5
3       6

What I want to do is to select the highest level value in every indicator.

Is there any sql query that I can use that will generate a result like this?

Level , Indicator

4       1
4       3 
4       5

If not, can you help me out using php and mysqli? Thank you so much.

Shadow
  • 33,525
  • 10
  • 51
  • 64
jeloneedshelp
  • 143
  • 2
  • 11

1 Answers1

2

To get Indicators having just highest level value -

select distinct Indicator, level
  from your_table
 where level = (select max(level) from your_table)

Also, you can use group by to get highest level for each Indicator value -

select Indicator, max(Level) from your_table group by Indicator
Jaydip Rakholiya
  • 792
  • 10
  • 20
  • also you could employ window functions for operating on a set of rows and return a single value for each row from the underlying query – Victor Sep 20 '18 at 22:29