I have two tables and I want to compare these two tables with a query( ie.
"select * from A where B.key = A.key") and the result will be stored in a
3rd table (table C). is this possible? If necessary, I can create the schema
for the 3rd table (C) since it'll be exactly like table A. But I'm more
interested in being able to store the resulting set into another table.
Thanks. 9 6603
VMI,
You can't really say:
select * from A where B.key = A.key
Because you don't know what the set of B is at that point. Are you
trying to check for the existence of the key in another table? If so, then
I would just do this:
select
a.*
from
a
inner join b on a.key = b.key
Since you use the field name "key", I'm assuming that each value is
unique, and therefore a one-to-one relationship exists.
If you perform this select, it will give you the same structure as A.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message
news:eQ******** ******@TK2MSFTN GP14.phx.gbl... I have two tables and I want to compare these two tables with a query( ie. "select * from A where B.key = A.key") and the result will be stored in a 3rd table (table C). is this possible? If necessary, I can create the schema for the 3rd table (C) since it'll be exactly like table A. But I'm more interested in being able to store the resulting set into another table.
Thanks.
> select a.*
into c from a inner join b on a.key = b.key
You're right about the query (it's been a long time since I've worked with
sql statements).
If I use this statement, where would I need to execute it in order to
compare datatable a and datatable b? Both tables are already filled with
data, and I need to store the data of the resulting set into a separate
table (which is a clone of a).
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:ei******** ******@TK2MSFTN GP11.phx.gbl... VMI,
You can't really say:
select * from A where B.key = A.key
Because you don't know what the set of B is at that point. Are you trying to check for the existence of the key in another table? If so, then I would just do this:
select a.* from a inner join b on a.key = b.key
Since you use the field name "key", I'm assuming that each value is unique, and therefore a one-to-one relationship exists.
If you perform this select, it will give you the same structure as A.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:eQ******** ******@TK2MSFTN GP14.phx.gbl...I have two tables and I want to compare these two tables with a query( ie. "select * from A where B.key = A.key") and the result will be stored in a 3rd table (table C). is this possible? If necessary, I can create the schema for the 3rd table (C) since it'll be exactly like table A. But I'm more interested in being able to store the resulting set into another table.
Thanks.
VMI,
That all depends on what kind of comparison are you doing? Are you
comparing A and B to see if the same keys exist in both tables? Or, where
the keys exist in both tables, the fields are the same?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message
news:ev******** ******@TK2MSFTN GP10.phx.gbl... You're right about the query (it's been a long time since I've worked with sql statements). If I use this statement, where would I need to execute it in order to compare datatable a and datatable b? Both tables are already filled with data, and I need to store the data of the resulting set into a separate table (which is a clone of a).
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:ei******** ******@TK2MSFTN GP11.phx.gbl... VMI,
You can't really say:
select * from A where B.key = A.key
Because you don't know what the set of B is at that point. Are you trying to check for the existence of the key in another table? If so, then I would just do this:
select a.* from a inner join b on a.key = b.key
Since you use the field name "key", I'm assuming that each value is unique, and therefore a one-to-one relationship exists.
If you perform this select, it will give you the same structure as A.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:eQ******** ******@TK2MSFTN GP14.phx.gbl...I have two tables and I want to compare these two tables with a query( ie. "select * from A where B.key = A.key") and the result will be stored in a 3rd table (table C). is this possible? If necessary, I can create the schema for the 3rd table (C) since it'll be exactly like table A. But I'm more interested in being able to store the resulting set into another table.
Thanks.
I'm just coparing the keys. For any matching keys between both tables (a &
b), I'll be copying the row from table a into my new table c. So I'll be
using the query you gave me, but I wouldn't know what other instructions I'd
execute it with.
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:eU******** ********@TK2MSF TNGP10.phx.gbl. .. VMI,
That all depends on what kind of comparison are you doing? Are you comparing A and B to see if the same keys exist in both tables? Or, where the keys exist in both tables, the fields are the same?
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:ev******** ******@TK2MSFTN GP10.phx.gbl... You're right about the query (it's been a long time since I've worked with sql statements). If I use this statement, where would I need to execute it in order to compare datatable a and datatable b? Both tables are already filled with data, and I need to store the data of the resulting set into a separate table (which is a clone of a).
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:ei******** ******@TK2MSFTN GP11.phx.gbl... VMI,
You can't really say:
select * from A where B.key = A.key
Because you don't know what the set of B is at that point. Are you trying to check for the existence of the key in another table? If so, then I would just do this:
select a.* from a inner join b on a.key = b.key
Since you use the field name "key", I'm assuming that each value is unique, and therefore a one-to-one relationship exists.
If you perform this select, it will give you the same structure as A.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:eQ******** ******@TK2MSFTN GP14.phx.gbl... I have two tables and I want to compare these two tables with a query( ie. "select * from A where B.key = A.key") and the result will be stored in a 3rd table (table C). is this possible? If necessary, I can create the schema for the 3rd table (C) since it'll be exactly like table A. But I'm more interested in being able to store the resulting set into another table.
Thanks.
This is the code I was initially using:
DataTable table_auditGrid = _table_auditAdd ress.Clone();
foreach (DataRow row in table_keys.Rows )
{
DataRow[] resultRow = _table_auditAdd ress.Select("co l_Key = '" +
row["key"] + "'");
if (resultRow.Leng th > 0)
{
table_auditGrid .Rows.Add(resul tRow[0]); //error saying that this
row already exists in another table
}
}
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:eU******** ********@TK2MSF TNGP10.phx.gbl. .. VMI,
That all depends on what kind of comparison are you doing? Are you comparing A and B to see if the same keys exist in both tables? Or, where the keys exist in both tables, the fields are the same?
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:ev******** ******@TK2MSFTN GP10.phx.gbl... You're right about the query (it's been a long time since I've worked with sql statements). If I use this statement, where would I need to execute it in order to compare datatable a and datatable b? Both tables are already filled with data, and I need to store the data of the resulting set into a separate table (which is a clone of a).
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:ei******** ******@TK2MSFTN GP11.phx.gbl... VMI,
You can't really say:
select * from A where B.key = A.key
Because you don't know what the set of B is at that point. Are you trying to check for the existence of the key in another table? If so, then I would just do this:
select a.* from a inner join b on a.key = b.key
Since you use the field name "key", I'm assuming that each value is unique, and therefore a one-to-one relationship exists.
If you perform this select, it will give you the same structure as A.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:eQ******** ******@TK2MSFTN GP14.phx.gbl... I have two tables and I want to compare these two tables with a query( ie. "select * from A where B.key = A.key") and the result will be stored in a 3rd table (table C). is this possible? If necessary, I can create the schema for the 3rd table (C) since it'll be exactly like table A. But I'm more interested in being able to store the resulting set into another table.
Thanks.
VMI,
Ahh, I see what you are doing now. I would actually query against the
database itself, as the query would be much, much quicker to execute.
However, for what you are doing, that is the right way, with one
exception. Instead of calling the Add method on the DataRowsCollect ion, you
should call the ImportRow method. This will copy the row into the new
table.
Also, to make it easier (and not have to rely on the Select method), you
might want to establish a DataRelation between the two tables (assuming they
are in the same data set). Once you do that, you can cycle through the rows
of the parent, and then call the GetChildRows method on the row, passing the
DataRelation in. If it returns null, then there are no related records,
otherwise, copy it over.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message
news:Ok******** ******@tk2msftn gp13.phx.gbl... This is the code I was initially using:
DataTable table_auditGrid = _table_auditAdd ress.Clone(); foreach (DataRow row in table_keys.Rows ) { DataRow[] resultRow = _table_auditAdd ress.Select("co l_Key = '" + row["key"] + "'"); if (resultRow.Leng th > 0) { table_auditGrid .Rows.Add(resul tRow[0]); //error saying that this row already exists in another table } } "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:eU******** ********@TK2MSF TNGP10.phx.gbl. .. VMI,
That all depends on what kind of comparison are you doing? Are you comparing A and B to see if the same keys exist in both tables? Or, where the keys exist in both tables, the fields are the same?
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:ev******** ******@TK2MSFTN GP10.phx.gbl... You're right about the query (it's been a long time since I've worked with sql statements). If I use this statement, where would I need to execute it in order to compare datatable a and datatable b? Both tables are already filled with data, and I need to store the data of the resulting set into a separate table (which is a clone of a).
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:ei******** ******@TK2MSFTN GP11.phx.gbl... VMI,
You can't really say:
select * from A where B.key = A.key
Because you don't know what the set of B is at that point. Are you trying to check for the existence of the key in another table? If so, then I would just do this:
select a.* from a inner join b on a.key = b.key
Since you use the field name "key", I'm assuming that each value is unique, and therefore a one-to-one relationship exists.
If you perform this select, it will give you the same structure as A.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:eQ******** ******@TK2MSFTN GP14.phx.gbl... >I have two tables and I want to compare these two tables with a >query( ie. "select * from A where B.key = A.key") and the result will >be stored in a 3rd table (table C). is this possible? If necessary, I >can create the schema for the 3rd table (C) since it'll be exactly like >table A. But I'm more interested in being able to store the resulting >set into another table. > > Thanks. >
Thanks for the help. It worked.
Vaughn
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:ew******** ******@TK2MSFTN GP15.phx.gbl... VMI,
Ahh, I see what you are doing now. I would actually query against the database itself, as the query would be much, much quicker to execute.
However, for what you are doing, that is the right way, with one exception. Instead of calling the Add method on the DataRowsCollect ion, you should call the ImportRow method. This will copy the row into the new table.
Also, to make it easier (and not have to rely on the Select method), you might want to establish a DataRelation between the two tables (assuming they are in the same data set). Once you do that, you can cycle through the rows of the parent, and then call the GetChildRows method on the row, passing the DataRelation in. If it returns null, then there are no related records, otherwise, copy it over.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:Ok******** ******@tk2msftn gp13.phx.gbl... This is the code I was initially using:
DataTable table_auditGrid = _table_auditAdd ress.Clone(); foreach (DataRow row in table_keys.Rows ) { DataRow[] resultRow = _table_auditAdd ress.Select("co l_Key = '" + row["key"] + "'"); if (resultRow.Leng th > 0) { table_auditGrid .Rows.Add(resul tRow[0]); //error saying that this row already exists in another table } } "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:eU******** ********@TK2MSF TNGP10.phx.gbl. .. VMI,
That all depends on what kind of comparison are you doing? Are you comparing A and B to see if the same keys exist in both tables? Or, where the keys exist in both tables, the fields are the same?
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"VMI" <vo******@yahoo .com> wrote in message news:ev******** ******@TK2MSFTN GP10.phx.gbl... You're right about the query (it's been a long time since I've worked with sql statements). If I use this statement, where would I need to execute it in order to compare datatable a and datatable b? Both tables are already filled with data, and I need to store the data of the resulting set into a separate table (which is a clone of a).
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:ei******** ******@TK2MSFTN GP11.phx.gbl... > VMI, > > You can't really say: > > select * from A where B.key = A.key > > Because you don't know what the set of B is at that point. Are you > trying to check for the existence of the key in another table? If so, > then I would just do this: > > select > a.* > from > a > inner join b on a.key = b.key > > Since you use the field name "key", I'm assuming that each value is > unique, and therefore a one-to-one relationship exists. > > If you perform this select, it will give you the same structure as > A. > > Hope this helps. > > > -- > - Nicholas Paldino [.NET/C# MVP] > - mv*@spam.guard. caspershouse.co m > > "VMI" <vo******@yahoo .com> wrote in message > news:eQ******** ******@TK2MSFTN GP14.phx.gbl... >>I have two tables and I want to compare these two tables with a >>query( ie. "select * from A where B.key = A.key") and the result will >>be stored in a 3rd table (table C). is this possible? If necessary, I >>can create the schema for the 3rd table (C) since it'll be exactly >>like table A. But I'm more interested in being able to store the >>resulti ng set into another table. >> >> Thanks. >> > >
VMI wrote: I'm just coparing the keys. For any matching keys between both tables (a & b), I'll be copying the row from table a into my new table c. So I'll be using the query you gave me, but I wouldn't know what other instructions
I'd execute it with.
For pure SQL, something like
insert into c
(
c.col1,
c.col2,
...
)
values
(
select
a.col1,
a.col2,
...
from
a t1,
b t2
where
t1.key = t2.key
);
might work.
Maybe you'll have to define the join explicitly like
from
a inner join b
on
a.key = b.key
like Nicholas suggested.
What's your database ? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rachel Curran |
last post by:
Please can anybody help me with the following:
I have two separate excel spreadsheets that I have imported into
access, each sheet holds the same fields. Both spreadsheets hold all
information for employees however, they are from two different dates
so by comparing both sheets I should to be able to check which records
DO NOT match. From...
|
by: Megan |
last post by:
Hi everybody-
I'm helping a friend with a music database. She has an old one and is
creating a new one. She wants to compare records and fields in the old
database with records and fields in the new database. For instance,
her old database has a table with Band Info in it. Her new database
also has a table with Band Info in it but slightly...
|
by: Vincent |
last post by:
has any one seen a program to compare mdbs'. I have ran into a few of
them, but none seem to really do that job.
Basically what I need to do is, take 2 access mdb's and check the
differences between the 2. i am talking about tables, forms, queries,
the whole ball of wax. Most of the programs jus do tables, that is
the easy part.
Also...
|
by: Edd E |
last post by:
Hi,
I have a database to store my analyses (Access 2002, WinXp), the basic structure is:
TABLE 1 = Sample Info
TABLE 2 = Analysis type 1
TABLE 3 = Analysis type 2
TABLE 4 = Analysis type 3
....where each table stores results of a different type of analysis
|
by: nyathancha |
last post by:
Hi,
I have a question regarding best practices in database design. In a
relational database, is it wise/necessary to sometimes create tables
that are not related to other tables through a foreign Key
relationship or does this always indicate some sort of underlying
design flaw. Something that requires a re evaluation of the problem
domain?...
| |
by: napatel04 |
last post by:
Hi everyone,
I would like to know if there is a quick query someone can help me
write for the following scenario. I think I can do this with VBA but
since this is suppose to be a temp. solution, I really do not want to
spend too much time on it.
I have two tables, 1 an old one which has work done in it with all the
necessary columns...
|
by: osward |
last post by:
Hi everyone,
I have query(s) that I need to perform which I couldn't figure out, and following is the situation
I have event table (which stores the event details) that has eid, date, time, place field, etc.
I have a member table (which stores who join which event) that has the same field eid as event table but with other member...
|
by: dbanrman |
last post by:
I have a module in a shopping cart program where a sellers logs in and adds product. As usual the seller logs in with an email and password which is stored in the mysql table _supplier_admins. This table also contains the field supplier_admin_name.
When the seller adds product they currently have the choice to select a manufacturer. For later...
|
by: chazzy69 |
last post by:
Ok heres what im trying to achive i am constantly updating the information in a table but know i what know if the data im replacing it with is new, i.e. whether or not i already had the data in the table.
So my method for this is to first copy the information to be updated into another table (the 2nd table), then allow the information in the...
|
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. ...
|
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...
| |
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |