473,480 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need Help On Multiple Max Values

2 New Member
i got a table like this

TABLE:
phonenum | crc | attempts | lastcalled
1234 | sd | 5 | 2007-1-08
1234 | ab | 8 | 2006-1-08
2345 | sd | 1 | 2007-1-08
2345 | sd | 5 | 2005-1-06

i need to get the latest date (lastcalled) then the following fields that will return an output like this: it will extract the latest lastcalled date.

OUTPUT:
phonenum | crc | attempts | lastcalled
1234 | sd | 5 | 2007-1-08
2345 | sd | 1 | 2007-1-08

what ive done so far is this:

select phonenum, crc, attempts, max(lastcalled) as lastcalled
from table
group by phonenum,crc, attempts

that query returned a value like this:
phonenum | crc | attempts | lastcalled
1234 | sd | 5 | 2007-1-08
1234 | ab | 8 | 2006-1-08
2345 | sd | 1 | 2007-1-08
2345 | sd | 5 | 2005-1-06

it didnt remove the previous lastcalled.
i need only the latest date and the column corresponds to the latest lastcalled column,
can someone help me thanks
Feb 19 '08 #1
4 1334
amitpatel66
2,367 Recognized Expert Top Contributor
i got a table like this

TABLE:
phonenum | crc | attempts | lastcalled
1234 | sd | 5 | 2007-1-08
1234 | ab | 8 | 2006-1-08
2345 | sd | 1 | 2007-1-08
2345 | sd | 5 | 2005-1-06

i need to get the latest date (lastcalled) then the following fields that will return an output like this: it will extract the latest lastcalled date.

OUTPUT:
phonenum | crc | attempts | lastcalled
1234 | sd | 5 | 2007-1-08
2345 | sd | 1 | 2007-1-08

what ive done so far is this:

select phonenum, crc, attempts, max(lastcalled) as lastcalled
from table
group by phonenum,crc, attempts

that query returned a value like this:
phonenum | crc | attempts | lastcalled
1234 | sd | 5 | 2007-1-08
1234 | ab | 8 | 2006-1-08
2345 | sd | 1 | 2007-1-08
2345 | sd | 5 | 2005-1-06

it didnt remove the previous lastcalled.
i need only the latest date and the column corresponds to the latest lastcalled column,
can someone help me thanks
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT x.phonenum, y.crc.y.attempts,x.lastcalled FROM
  3. (SELECT phonenum,max(lastcalled) lastcalled FROM table GROUP BY phonenum) x, table y
  4. WHERE x.phonenum = y.phonenumn
  5. AND x.lastcalled = y.lastcalled
  6.  
  7.  
Feb 19 '08 #2
gcleffff
2 New Member
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT x.phonenum, y.crc.y.attempts,x.lastcalled FROM
  3. (SELECT phonenum,max(lastcalled) lastcalled FROM table GROUP BY phonenum) x, table y
  4. WHERE x.phonenum = y.phonenumn
  5. AND x.lastcalled = y.lastcalled
  6.  
  7.  
many thanks to you it worked im still a noob at querying can you give me some tips on where to learn more or what book do i need to be a master like you thanks a lot
Feb 19 '08 #3
amitpatel66
2,367 Recognized Expert Top Contributor
many thanks to you it worked im still a noob at querying can you give me some tips on where to learn more or what book do i need to be a master like you thanks a lot
Look for some online books on MSSQL and start learning basics
Feb 20 '08 #4
cathy25
21 New Member
Another way of the same query is

Select Phonenum,max(lastcalled) from Table
group by Phonenum
order by Phonenum
Feb 22 '08 #5

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

Similar topics

15
7359
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
66
4896
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
1
2531
by: John Smith | last post by:
I have a user assigned multiple roles and a role can be inherited from multiple parents (see below). How do I answer such questions as "How many roles does the user belongs to?" I answered the...
3
4320
by: Steve | last post by:
i pulled an example off the web and modified it somewhat and whats killimg me is that sometimes it works and sometimes it doesnt. the following is the only line that allows this thing to work over...
10
2847
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
23
2558
by: Adam | last post by:
I am coding a microkernel based off of Tanebaum's theroy. For Isis to be extensible, fast, and secure, it has been decided it will be a microkernel. Not in the old Mach sense of the word, but in...
13
1621
by: Jeff Davis | last post by:
Right now performance isn't a problem, but this question has me curious: Let's say I have a shopping cart system where there is a "products" table that contains all possible products, and an...
3
4380
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
0
1874
by: rich | last post by:
I have a database with 1 to many and the many is a list with multiple selects in a list. When I click on a master record I have as part of my form the select statement for the multiple choice...
1
2741
by: v4u2chat | last post by:
Do I need to extend any of classes from AXIS to return multiple values? I'm exposing the following method as web service through AXIS to return multiple values. public ContactAddress...
0
7037
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
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7076
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...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5321
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,...
1
4767
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.