473,569 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query help -- extract data, thanks!

Hello,

Please see the original data below. I would like to extract the account
with the earliest opening date only, and leave all the accounts opened
after that out. Could anybody help me with the query? Thanks a lot!

Original Data
person_id account open_date
10001 1111111 5/15/2003
10001 2222222 6/20/2004
10001 3333333 2/16/2005

Ideal Output
person_id account open_date
10001 1111111 5/15/2003

Jul 23 '05 #1
7 1394
Select *
From OriginalData O

Where Open_Date = (Select MIN(Open_Date) From OriginalData Where
Person_ID = O.Person_ID)

Let me know if it errors out....!!!!

Jul 23 '05 #2
Sorry guys... These crazy '>' kills the script....!!! Here is the clean
version again...!

Select *
From OriginalData O

Where Open_Date = (Select MIN(Open_Date) From OriginalData Where
Person_ID = O.Person_ID)

Jul 23 '05 #3
Not sure why it keeps messing my text.... Google needs to fix
this.....!!!!!! ! tough luck.. I dont want to even try formating it
again....

Jul 23 '05 #4
Thanks! It works!

However, when I tried another set of raw data which has two person_id
(please see below), I only got one record in output, while I am
expecting two. Any clue? Thanks!

Select *
From test Where zip = (Select MIN(zip) From test Where
Person_ID = test.Person_ID)

Raw Data
person_id zip state
10001 11111 AA
10001 22222 BB
10002 11113 AA

Output
person_id zip state
10001 11111 AA

Ideal Output
person_id zip state
10001 11111 AA
10002 11113 AA

Query Builder wrote: Select *
From OriginalData O

Where Open_Date = (Select MIN(Open_Date) From OriginalData Where
Person_ID = O.Person_ID)

Let me know if it errors out....!!!!


Jul 23 '05 #5
No worries about the re-formatting! I got the same problem... I will
delete them before running the query. Thanks.

Jul 23 '05 #6
On 16 Mar 2005 11:45:29 -0800, ro******@gmail. com wrote:
Thanks! It works!

However, when I tried another set of raw data which has two person_id
(please see below), I only got one record in output, while I am
expecting two. Any clue? Thanks!

(snip)

Hi rong.guo,

Your query is for the person (or persons) with the lowest ZIP code. The
output you expect shows two ZIP codes: 11111 and 11113. Is this because
you actually wanted the 2 lowest ZIP codes, or because you actually
wanted the lowest state?

For lowest state try

SELECT person_id, zip, state
FROM test AS t1
WHERE state = (SELECT MIN(state)
FROM test AS t2
WHERE t2.Person_ID = t1.Person_ID)

For the 2 lowest ZIP codes, try

SELECT TOP 2 person_id, zip, state
FROM test
ORDER BY zip

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #7
Thanks Hugo!

What I wanted is the lowest zip code for EACH PERSON, together with the
state of the lowest zip code. Because some people do have multiple zip
codes and states, the idea is to only keep the lowest zip, and get rid
of others. Your query works well, I only changed min(state) to
min(zip).

Thanks again!

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3909
by: Joe Gazda | last post by:
I'm a relative newbie to PHP, but have been able to put together some PHP code to generate a CSV/XLS file from a Query result. Now, I would like to include custom column names instead of the MySQL column table names. I know that there are codes to generate tabs and carriage returns, but can't find anything about including "commas" in a string...
9
3115
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be...
6
29929
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access newsgroups, the access support centre, I can seem to find no similar situation. I am not using any references, or VBA at all in the first place....
2
306
by: EricD | last post by:
Hi, I just started using access. I have a fairly simple data base that contains 2 identical tables: Table 1 contains data from the previous week and Table 2 contains data for the current week. Some Data (name of customer)may appear in both tables. I know how to make a query that will give the data that appears in Both
3
2082
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance you can provide. I have a table in an Access 2000 .mdb file, and I've run into something odd and insolvable, at least for me. The database is for membership information. This particular table, called tblMembershipInfo, has fields/columns as follows - fldMemNum - Member Number...
3
4341
by: RLN | last post by:
Re: Access 2003/Oracle 9i I have an Access app that connects to an Oracle DB via OLEDB/VBA code (no DSN or ODBC) Queries against straight Oracle tables run fine. For this query, however, the condition for finding DeptID's in the Oracle table have to be filtered by a list of DeptID's found in "tblDeptID" which is a simple local Access...
1
1962
by: b0red | last post by:
Hi All, Thanks for taking the time to read this post, I appreciate it. Two problems Problem 1 --------- I need help with a query the table contains 35 odd columns I only want fname, lname,and age . I'd like to dump the results as a single file in the following format: As after I have dumped the results I need to import them into...
5
2076
by: Samik2003 | last post by:
Hello, The problem is my query is not extracting the correct xml data from the database : Is there something which I am missing?? ANy help would be appriciated. Thanks, Sam. THis is the query which I am using to extract :
2
1903
by: Dinesh | last post by:
Hi experts, I am working on SQL Server 2005. Now i have to write a query which will extract some information from a table. My main table is having few columns supose 3 columns. EmpID Supervisor_ID Date_Of_Visit Now records are entering in this tabl. Date of visit is date of
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6286
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5222
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
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 we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.