473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

max command

My file has 2 fields : seqno and date
There can be lots of records for each seqno.
For each seqno, the date can be either set, or nulls.

How do I use the max function to return only the highest seqno which has a date set ?
ie ignoring those where the highest seqno is null ?

Thanks
Feb 18 '11 #1
7 1783
JKing
1,206 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(seqno)
  2. FROM your_table
  3. WHERE date IS NOT NULL
  4.  
Feb 18 '11 #2
thanks J
This gives me one value for all the different sequence numbers.

If I have :-
ref seq date
1 1 1/1/11
1 2 1/3/11
1 3 1/5/11
2 1 2/1/11
2 2 null
3 1 2/10/11
3 2 2/11/11

then I would like the following as my output :-
1 3 1/5/11
3 2 2/11/11

Sorry if I wasn't clear enough earlier.
Feb 18 '11 #3
JKing
1,206 Expert 1GB
Does 2 1 2/1/11 also fit in that list?

Do you want the highest seqno for each ref where the date is not null?
Feb 18 '11 #4
Hi J
I do indeed only want the highest seqno for each ref where the date is not null. So ref 2 would be excluded entirely. Many thanks for your ongoing help.
Feb 18 '11 #5
JKing
1,206 Expert 1GB
Why would ref 2 be excluded? Should it not fallback to seqno 1 as it would be the highest seqno where the date is not null for that ref.
Feb 18 '11 #6
Hi J
It is to be exluded because that is how it is defined in my spec. Unfortunately, I do not know enough about the system to determine what you are suggesting is true or not. I would be most grateful therefore if you can give a suggestion based on Ref 2, and all similar cases, being excluded.
Many thanks again.
Feb 18 '11 #7
JKing
1,206 Expert 1GB
Fair enough.

Expand|Select|Wrap|Line Numbers
  1. SELECT your_table.ref, your_table.seqno, your_table.`date` 
  2. FROM (
  3.         SELECT ref, MAX(seqno) as seqno FROM your_table GROUP BY ref
  4.      ) AS sub_query
  5.      JOIN your_table ON your_table.ref = sub_query.ref AND your_table.seqno = sub_query.seqno
  6. WHERE your_table.`date` IS NOT NULL
  7.  
Change all references of your_table to your table's name.
Feb 18 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: TEK | last post by:
Hello I'm wondering if anyone out there might give some input/suggestions/viewpoints around the Command pattern. In my case, the number one priority for using the pattern is undo support. Some...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
12
by: Rhino | last post by:
I am having an odd problem: the sqlj command on my system doesn't work. I am running DB2 (LUW) V8 (FP8) on WinXP. I haven't done an sqlj program since Version 6 of DB2 (LUW) so I checked the...
2
by: micahstrasser | last post by:
I have been trying for days to send a command to the command prompt through the shell() function in vb.net. For some reason it is not working. Here is the code: Private Sub Button1_Click(ByVal...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
0
by: czerwww | last post by:
Can someone please help me? I have class for database connection and I need set command.commandTimeout. How can I do that? Code: Imports System.Data.SqlClient Imports System.Data Public Class...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.