Help on INSERT INTO SQL

G

Guest

Can someone please help me out on this and correct my SQL so it actually
works? This is what I have so far and it's not pretty:

INSERT INTO Table1 ([MinVol]) SELECT MIN([Volume]) FROM Table2
WHERE Table1.[Symbol] = Table2.[Symbol] GROUP BY Table2.[Volume];

What I want is the minimum value of VOLUME found in TABLE2 inserted into the
field "MinVol" in TABLE1 where ever Table1.[Symbol] = Table2.[Symbol].

Thanks much in advance for your assistance.
 
M

Marshall Barton

quartz said:
Can someone please help me out on this and correct my SQL so it actually
works? This is what I have so far and it's not pretty:

INSERT INTO Table1 ([MinVol]) SELECT MIN([Volume]) FROM Table2
WHERE Table1.[Symbol] = Table2.[Symbol] GROUP BY Table2.[Volume];

What I want is the minimum value of VOLUME found in TABLE2 inserted into the
field "MinVol" in TABLE1 where ever Table1.[Symbol] = Table2.[Symbol].


An INSERT INTO query appends records to a table. You want
to use an UPDATE query. Unfortunately, Update queries have
trouble dealing with a subquery so you will probably have to
use DMin instead of the subquery.
 
G

Guest

Use this update when Symbol is String
UPDATE Table1 SET Table1.MinVol = DMin("volume","Table2","Symbol ='" &
[Symbol] & "'")
========================================
Use this update when Symbol is Number
UPDATE Table1 SET Table1.MinVol = DMin("volume","Table2","Symbol =" &
[Symbol])
========================================
 
G

Guest

Thanks!

Ofer said:
Use this update when Symbol is String
UPDATE Table1 SET Table1.MinVol = DMin("volume","Table2","Symbol ='" &
[Symbol] & "'")
========================================
Use this update when Symbol is Number
UPDATE Table1 SET Table1.MinVol = DMin("volume","Table2","Symbol =" &
[Symbol])
========================================



quartz said:
Can someone please help me out on this and correct my SQL so it actually
works? This is what I have so far and it's not pretty:

INSERT INTO Table1 ([MinVol]) SELECT MIN([Volume]) FROM Table2
WHERE Table1.[Symbol] = Table2.[Symbol] GROUP BY Table2.[Volume];

What I want is the minimum value of VOLUME found in TABLE2 inserted into the
field "MinVol" in TABLE1 where ever Table1.[Symbol] = Table2.[Symbol].

Thanks much in advance for your assistance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top