473,386 Members | 1,962 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,386 software developers and data experts.

need help to take the variables associated with the 1st occurrence of a date variable

Hi,

I am trying to join two tables, one has multiple records per ID, the
other is unique record per ID.
The two tables look like below
A
ID date var1 var 2
001 1/1 10 20
001 2/1 12 15
001 3/1 17 18
002 2/1 13 10
002 3/1 12 14
............

B
ID
001
002
003
004
....

The join conditions are
1. table A's ID = table B's ID
2. take the variables associated with the 1st occrrence of the date
variable in table A's

I have the following SQL code but the it didn't work. It says the
columns are ambiguously defined. Anyone can help me? Greatly appreciate
it!

PROC SQL;
CONNECT TO ORACLE (USER="&user" PASS="&pass" PATH="@POWH17"
BUFFSIZE=25000);

CREATE TABLE actvy1_1st AS SELECT * FROM CONNECTION TO ORACLE
(
SELECT
actvy1.ID,
actvy1.var1,
actvy1.var2,
actvy1.date

from
A actvy1,
(select a.ID,
min(a.date) mindate
from A a,
B c
where a.ID =c.ID
group by ID
) b

where actvy1.ID =b.ID
and actvy1.date =b.mindate
order by ID
);
disconnect from oracle;
quit;

Mar 8 '06 #1
3 1325
i'm betting this is homework, and you havent' learned enough in your
class to know that Oracle is different from SQL Server?

Mar 8 '06 #2
qualify ID in:

group by ID
order by ID

Mar 8 '06 #3
(me*********@gmail.com) writes:
I have the following SQL code but the it didn't work. It says the
columns are ambiguously defined. Anyone can help me? Greatly appreciate
it!

PROC SQL;
CONNECT TO ORACLE (USER="&user" PASS="&pass" PATH="@POWH17"
BUFFSIZE=25000);
Oracle? This is an SQL Server newsgroup!
CREATE TABLE actvy1_1st AS SELECT * FROM CONNECTION TO ORACLE
(
SELECT
actvy1.ID,
actvy1.var1,
actvy1.var2,
actvy1.date

from
A actvy1,
(select a.ID,
min(a.date) mindate
from A a,
B c
where a.ID =c.ID
group by ID


This line appears to be the culprit.

And I wonder, should you really have B in the derived table?
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 8 '06 #4

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

Similar topics

3
by: Johnd | last post by:
Is there a server-side event that fires when the session variable expires that i can trap and do something with (ie renew the session Variable or say run an asp to update a database) John,
1
by: Mario | last post by:
If there is an associated memory cost for using session variables, can the memory used be reclaimed on an ASP page by setting the session variable to undefined or null? If on the same ASP page you...
3
by: Richard Treadgold | last post by:
Is there a way to use variables on a web page? I suppose I mean simple text replacements, such as replacing each occurrence of the expression, say, "title" with "World Encycopaedia of Insects"....
6
by: Raqueeb Hassan | last post by:
Hello There! Have you guys tried inserting variables in mySQL tables? Do I have to use 'quote' as we had been doing to insert strings? mysql> INSERT INTO occurrence (word_id,page_id) VALUES...
13
by: EggsAckley | last post by:
Hi: I have a file that I have been told is a SQL Server backup from a server somewhere. The file is about 200MB in size I am trying to create the database on my local server using RESTORE. I...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
14
by: Rick | last post by:
We are in the process of testing a large web project that I converted from VS 2003 to VS 2005. Everything seems to be working except for a few minor things. But the main issue I have is this, I...
5
by: Charles May | last post by:
Anyone have a simple concept for the best way to store timeclock information in a database. I currently have my table set up like this with a typical daily entry. tcID empID Type ...
103
by: chochote | last post by:
Hi, I have a PHP script that does some processing, and stores an error message as a variable. The script then redirects to another script with the error string in the URL, with the second script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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,...

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.