Selecting Row Number in SQL Where Clause

KenHudson

New Member
Joined
Apr 4, 2013
Messages
22
I'm not versed in SQL and am trying to append a field of data from one table to another. The only criteria I want is to use the data in the first record of the "donor" table.
How can I phrase the Where clause correctly?

INSERT INTO Table1 ( LastDate )
SELECT Table2.NewDate
FROM Table2
WHERE (([Table2].RecordNumber)=1);
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
there really is no such thing as a record number

you can put an "order by" clause in your sql and it will bring records back in that order

so you could write these
Code:
select LastName, JoinDate, Zipcode from person 
order by Lastname 

select LastName, JoinDate, Zipcode from person 
order by JoinDate 

select LastName, JoinDate, Zipcode from person 
order by ZipCode

and each of them would have a different row show up as RecornNumber 1

your best bet is to use an order by clause or figure out if there is a "minimum" value in a column you can use

like
Code:
select PersonID, Amt_Purchased 
from some_table 
where 
Amt_Purchased  = 
(
  select min(Amt_Purchased)
  from some_table 
)
 
Upvote 0
Thanks for the response James.
The problem is that every record has the same date in it.
So the query wants to append every record and I only want to append the date once.
What code other than "min" will select only one record's date?

INSERT INTO tbl_Processing_Date ( ProcessingDate )
SELECT Run_Date
FROM F829
WHERE
Run_Date=(select min(Run_Date) from F829);
 
Upvote 0
This code seems to work:

INSERT INTO tbl_Processing_Date ( ProcessingDate )
SELECT F829.Run_Date
FROM F829
GROUP BY F829.Run_Date;
 
Upvote 0

Forum statistics

Threads
1,221,875
Messages
6,162,563
Members
451,775
Latest member
Aiden Jenner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top