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

query or script

I have a table with 2 fields where one has duplicates and the other
does not

something like this:

ID field1 field2
1 A A
2 A B
3 A C
4 A D
5 B E
6 B F
7 B G
8 B H

I'd like to select 2 records where field1 is A and 2 records where
field1 is B and insert it into a new table and also delete the
selected records from the table
I'm sure if this can be accomplished with a query or combination of
queries or I need to write a VBA script

any help appreciated

Jul 19 '08 #1
7 1732
nofear wrote:
I have a table with 2 fields where one has duplicates and the other
does not

something like this:

ID field1 field2
1 A A
2 A B
3 A C
4 A D
5 B E
6 B F
7 B G
8 B H

I'd like to select 2 records where field1 is A and 2 records where
field1 is B and insert it into a new table and also delete the
selected records from the table
I'm sure if this can be accomplished with a query or combination of
queries or I need to write a VBA script

any help appreciated
You could do something like
Select * From Table Where ID In (2,3,6,7)
and from that make MakeTable/Delete queries.

If this is a one time thing, that's what I'd do. If not, I figure you
can make some queries to do what you want but I'd go with code using
queries...maybe a form.
Jul 19 '08 #2
nofear <eu*******@hotmail.comwrote in
news:ea01d8bd-f8f7-4138-ba7d-df8a63cc2173@
25g2000hsx.googlegroups.com
:
I have a table with 2 fields where one has duplicates and the
other does not

something like this:

ID field1 field2
1 A A
2 A B
3 A C
4 A D
5 B E
6 B F
7 B G
8 B H

I'd like to select 2 records where field1 is A and 2 records where
field1 is B and insert it into a new table and also delete the
selected records from the table
I'm sure if this can be accomplished with a query or combination
of queries or I need to write a VBA script

any help appreciated
What should be done with the data in field2?
If you do not want it included in the new table, then use a query
with the distinct property set.

INSERT INTO newtable (ID,Field1) values (
SELECT DISTINCT ID, Field1 FROM oldtable);

If you need one value from field2, we'll need to know how to choose
the right one before making suggestions.

--
Bob Quintal

PA is y I've altered my email address.
** Posted from http://www.teranews.com **
Jul 20 '08 #3
The field1 really matters
I want to select the whole record (row) if the value in field1 is the
same but not all of them
simply I want to divide the data to 2 tables
if I have 4 records where the value in field1 is the same I want to
select 2 records and inser them into a new table
I fid it dificult to do with SQL


On Jul 20, 8:41*am, Bob Quintal <rquin...@sPAmpatico.cawrote:
nofear <euroli...@hotmail.comwrote in
news:ea01d8bd-f8f7-4138-ba7d-df8a63cc2173@
25g2000hsx.googlegroups.com
:
I have a table with 2 fields where one has duplicates and the
other does not
something like this:
ID * * field1 * * field2
1 * * *A * * * * * *A
2 * * *A * * * * * *B
3 * * *A * * * * * *C
4 * * *A * * * * * *D
5 * * *B * * * * * *E
6 * * *B * * * * * *F
7 * * *B * * * * * *G
8 * * *B * * * * * H
I'd like to select 2 records where field1 is A and 2 records where
field1 is B and insert it into a new table and also delete the
selected records from the table
I'm sure if this can be accomplished with a query or combination
of queries or I need to write a VBA script
any help appreciated

What should be done with the data in field2?
If you do not want it included in the new table, then use a query
with the distinct property set.

INSERT INTO newtable (ID,Field1) values (
SELECT DISTINCT ID, Field1 FROM oldtable);

If you need one value from field2, we'll need to know how to choose
the right one before making suggestions.

--
Bob Quintal

PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**
Jul 21 '08 #4
nofear <eu*******@hotmail.comwrote in news:d8343373-3a94-484b-
af***************@26g2000hsk.googlegroups.com:
The field1 really matters
I want to select the whole record (row) if the value in field1 is
the
same but not all of them
simply I want to divide the data to 2 tables
if I have 4 records where the value in field1 is the same I want
to
select 2 records and inser them into a new table
I fid it dificult to do with SQL

The easiest way is to copy the table structure to a new table, using
the save as dialog, with no records, then creating a query that
selects only the two important fields, with the distinct property
(or keyword). Convert that into an Append (Insert) query, into the
new table.

To get data from the other fields, if necessary, use an update query
that usesv dlookup() functions.
>

On Jul 20, 8:41*am, Bob Quintal <rquin...@sPAmpatico.cawrote:
>nofear <euroli...@hotmail.comwrote in
news:ea01d8bd-f8f7-4138-ba7d-df8a63cc2173@
25g2000hsx.googlegroups.com
:
I have a table with 2 fields where one has duplicates and the
other does not
something like this:
ID * * field1 * * field2
1 * * *A * * * * * *A
2 * * *A * * * * * *B
3 * * *A * * * * * *C
4 * * *A * * * * * *D
5 * * *B * * * * * *E
6 * * *B * * * * * *F
7 * * *B * * * * * *G
8 * * *B * * * * * H
I'd like to select 2 records where field1 is A and 2 records
where
field1 is B and insert it into a new table and also delete the
selected records from the table
I'm sure if this can be accomplished with a query or
combination
of queries or I need to write a VBA script
any help appreciated

What should be done with the data in field2?
If you do not want it included in the new table, then use a query
with the distinct property set.

INSERT INTO newtable (ID,Field1) values (
SELECT DISTINCT ID, Field1 FROM oldtable);

If you need one value from field2, we'll need to know how to
choose
>the right one before making suggestions.

--
Bob Quintal

PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**


--
Bob Quintal

PA is y I've altered my email address.
** Posted from http://www.teranews.com **
Jul 22 '08 #5
On Jul 21, 10:05*pm, Bob Quintal <rquin...@sPAmpatico.cawrote:
nofear <euroli...@hotmail.comwrote in news:d8343373-3a94-484b-
afcb-5f01cfe2d...@26g2000hsk.googlegroups.com:
The field1 really matters
I want to select the whole record (row) if the value in field1 is
the
same but not all of them
simply I want to divide the data to 2 tables
if I have 4 records where the value in field1 is the same I want
to
select 2 records and inser them into a new table
I fid it dificult to do with SQL

The easiest way is to copy the table structure to a new table, using
the save as dialog, with no records, then creating a query that
selects only the two important fields, with the distinct property
(or keyword). Convert that into an Append (Insert) query, into the
new table.

To get data from the other fields, if necessary, use an update query
that usesv dlookup() functions.


On Jul 20, 8:41*am, Bob Quintal <rquin...@sPAmpatico.cawrote:
nofear <euroli...@hotmail.comwrote in
news:ea01d8bd-f8f7-4138-ba7d-df8a63cc2173@
25g2000hsx.googlegroups.com
:
I have a table with 2 fields where one has duplicates and the
other does not
something like this:
ID * * field1 * * field2
1 * * *A * * * * * *A
2 * * *A * * * * * *B
3 * * *A * * * * * *C
4 * * *A * * * * * *D
5 * * *B * * * * * *E
6 * * *B * * * * * *F
7 * * *B * * * * * *G
8 * * *B * * * * * H
I'd like to select 2 records where field1 is A and 2 records
where
field1 is B and insert it into a new table and also delete the
selected records from the table
I'm sure if this can be accomplished with a query or
combination
of queries or I need to write a VBA script
any help appreciated
What should be done with the data in field2?
If you do not want it included in the new table, then use a query
with the distinct property set.
INSERT INTO newtable (ID,Field1) values (
SELECT DISTINCT ID, Field1 FROM oldtable);
If you need one value from field2, we'll need to know how to
choose
the right one before making suggestions.
--
Bob Quintal
PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**

--
Bob Quintal

PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**
I see
I would have to rerun this query with different property
I think I use this technique but I have to wite a VBA script that will
change the property and run the query till EOF

Jul 22 '08 #6
nofear <eu*******@hotmail.comwrote in
news:952384f0-70e2-4b28-a46e-464bc13277b7@
56g2000hsm.googlegroups.com
:
On Jul 21, 10:05*pm, Bob Quintal <rquin...@sPAmpatico.cawrote:
>nofear <euroli...@hotmail.comwrote in news:d8343373-3a94-484b-
afcb-5f01cfe2d...@26g2000hsk.googlegroups.com:
The field1 really matters
I want to select the whole record (row) if the value in field1
is
the
same but not all of them
simply I want to divide the data to 2 tables
if I have 4 records where the value in field1 is the same I
want
to
select 2 records and inser them into a new table
I fid it dificult to do with SQL

The easiest way is to copy the table structure to a new table,
using the save as dialog, with no records, then creating a query
that selects only the two important fields, with the distinct
property (or keyword). Convert that into an Append (Insert)
query, into the new table.

To get data from the other fields, if necessary, use an update
query that usesv dlookup() functions.


On Jul 20, 8:41*am, Bob Quintal <rquin...@sPAmpatico.cawrote:
nofear <euroli...@hotmail.comwrote in
news:ea01d8bd-f8f7-4138-ba7d-df8a63cc2173@
25g2000hsx.googlegroups.com
:
I have a table with 2 fields where one has duplicates and
the other does not
something like this:
ID * * field1 * * field2
1 * * *A * * * * * *A
2 * * *A * * * * * *B
3 * * *A * * * * * *C
4 * * *A * * * * * *D
5 * * *B * * * * * *E
6 * * *B * * * * * *F
7 * * *B * * * * * *G
8 * * *B * * * * * H
I'd like to select 2 records where field1 is A and 2 records
where
field1 is B and insert it into a new table and also delete
the selected records from the table
I'm sure if this can be accomplished with a query or
combination
of queries or I need to write a VBA script
any help appreciated
>What should be done with the data in field2?
If you do not want it included in the new table, then use a
query with the distinct property set.
>INSERT INTO newtable (ID,Field1) values (
SELECT DISTINCT ID, Field1 FROM oldtable);
>If you need one value from field2, we'll need to know how to
choose
>the right one before making suggestions.
>--
Bob Quintal
>PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**

--
Bob Quintal

PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**

I see
I would have to rerun this query with different property
I think I use this technique but I have to wite a VBA script that
will change the property and run the query till EOF

SQL is a powerful language. You can do this in one query, with the
properties selected by the query itself. However, if you are more
confident using a recordset, that is acceptable.
--
Bob Quintal

PA is y I've altered my email address.
** Posted from http://www.teranews.com **
Jul 22 '08 #7
then I gues I have to seek for help in a SQL group
On Jul 22, 9:25*am, Bob Quintal <rquin...@sPAmpatico.cawrote:
nofear <euroli...@hotmail.comwrote in
news:952384f0-70e2-4b28-a46e-464bc13277b7@
56g2000hsm.googlegroups.com
:
On Jul 21, 10:05*pm, Bob Quintal <rquin...@sPAmpatico.cawrote:
nofear <euroli...@hotmail.comwrote in news:d8343373-3a94-484b-
afcb-5f01cfe2d...@26g2000hsk.googlegroups.com:
The field1 really matters
I want to select the whole record (row) if the value in field1
is
the
same but not all of them
simply I want to divide the data to 2 tables
if I have 4 records where the value in field1 is the same I
want
to
select 2 records and inser them into a new table
I fid it dificult to do with SQL
The easiest way is to copy the table structure to a new table,
using the save as dialog, with no records, then creating a query
that selects only the two important fields, with the distinct
property (or keyword). Convert that into an Append (Insert)
query, into the new table.
To get data from the other fields, if necessary, use an update
query that usesv dlookup() functions.
On Jul 20, 8:41*am, Bob Quintal <rquin...@sPAmpatico.cawrote:
nofear <euroli...@hotmail.comwrote in
news:ea01d8bd-f8f7-4138-ba7d-df8a63cc2173@
25g2000hsx.googlegroups.com
:
I have a table with 2 fields where one has duplicates and
the other does not
something like this:
ID * * field1 * * field2
1 * * *A * * * * * *A
2 * * *A * * * * * *B
3 * * *A * * * * * *C
4 * * *A * * * * * *D
5 * * *B * * * * * *E
6 * * *B * * * * * *F
7 * * *B * * * * * *G
8 * * *B * * * * * H
I'd like to select 2 records where field1 is A and 2 records
where
field1 is B and insert it into a new table and also delete
the selected records from the table
I'm sure if this can be accomplished with a query or
combination
of queries or I need to write a VBA script
any help appreciated
What should be done with the data in field2?
If you do not want it included in the new table, then use a
query with the distinct property set.
INSERT INTO newtable (ID,Field1) values (
SELECT DISTINCT ID, Field1 FROM oldtable);
If you need one value from field2, we'll need to know how to
choose
the right one before making suggestions.
--
Bob Quintal
PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**
--
Bob Quintal
PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**
I see
I would have to rerun this query with different property
I think I use this technique but I have to wite a VBA script that
will change the property and run the query till EOF

SQL is a powerful language. You can do this in one query, with the
properties selected by the query itself. However, if you are more
confident using a recordset, that is acceptable.

--
Bob Quintal

PA is y I've altered my email address.
** Posted fromhttp://www.teranews.com**
Jul 23 '08 #8

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

Similar topics

4
by: Joe | last post by:
I have wrote a script to query my mysql database based up a name that is selected from an HTML list menu, the form action calls to my php script from my html doc, I have tested connectivity to the...
14
by: Bob | last post by:
Hi there, Need a little help with a certain query that's causing a lot of acid in my stomach... Have a table that stores sales measures for a given client. The sales measures are stored per...
8
by: dstefani | last post by:
Hello, I was wondering if you can get the info from the query string in a server-side javascript tag? Here's what I'm trying to do In the head of page A ....
4
by: news-server.tampabay.rr.com | last post by:
Hi, Below is a stock script I found which controls a framed environment. My problem is that if a URL has a query string attached, that string does not pass through. Can someone please let me...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
1
by: Aaron West | last post by:
Try this script to see what queries are taking over a second. To get some real output, you need a long-running query. Here's one (estimated to take over an hour): PRINT GETDATE() select...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: ...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
3
by: deppeler | last post by:
How do I reload a parent window that is part of a cgi script that has a query string? I have a script that shows a record with images uploaded into a DB. I have an image upload script (child...
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: 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: 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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.