Jump to content

Recommended Posts

Hi everyone,

 

I have a table set up as such:

 

name | extension | id

de01  | NULL        | 1

de01  | NULL        | 2

de01  | 01            | 3

de01  | NULL        | 4

de01  | 01            | 5

de01  | 02            | 6

de01  | 02            | 7

 

What I am trying to do is output only the records with the highest value in the "extension" column. So based on the table above I would like to output the following:

 

de01 | 02 | 6

de01 | 02 | 7

 

Additionally, this would have to be a query that can handle higher extensions that may be entered in the future. Example: if a new record was added that contained de01 | 03, that would now need to be shown and the previous two de01 | 02 records would no longer show up. I tried MAX() but I can't seem to get it to function that way I need it.

 

Thanks in advance for your time.

Hi Premiso,

 

I changed the extension column over to integer and am still having an issue, I think because of the group clause.

 

Here is the SQL statement:

 

"SELECT *, MAX(eo_engine_family.executive_order_extension) AS ext
FROM executive_order
INNER JOIN eo_engine_family ON ( executive_order.executive_order = eo_engine_family.executive_order_new )
INNER JOIN engine_family_offroad_cal ON ( eo_engine_family.engine_family_name = engine_family_offroad_cal.engine_family_name )
WHERE executive_order.date_eo_rescinded IS NULL
AND executive_order.date_eo_rescinded IS NULL
AND eo_engine_family.engine_family_name = '".$engine_family_name."'
eo_engine_family.id
ORDER BY engine_year

 

This is outputting ALL results and not just the "highest" value in the extension column.

 

Thanks in advance.

 

-SC

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.