Hiya
I'm new to SQL so I hope somebody can help me with the following:
Suppose I have two tables. How can I find if the two have "identical rows";
in the sense that they are allowed to have different primary keys but in
respect to all the other fields they are the same.
Thanks in advance
Geoff 4 1580
Geoff Jones wrote: Suppose I have two tables. How can I find if the two have "identical rows"; in the sense that they are allowed to have different primary keys but in respect to all the other fields they are the same.
You need to join those two tables and search rows where all wanted
columns have similar values. Something like this:
select
table1.id as table1_id,
table2.id as table2_id
from table1,table2
where
table1.column1 = table2.column1 and
table1.column2 = table2.column2 and
table1.column3 = table2.column3;
Be aware that this can return the same id values multiple times if you
got multiple duplicates.
Hiya Aggro
Forgive my ignorance, but like I say, I'm a beginner at this stuff, but
could you explain:
select
table1.id as table1_id,
table2.id as table2_id
from table1,table2
i.e. I'm a little puzzed by the "table1.id as table1_id" (the last bit)
Is table1.id the primary key of table1? What is table1_id?
Geoff
"Aggro" <sp**********@y ahoo.com> wrote in message
news:Xm******** *******@read3.i net.fi... Geoff Jones wrote:
Suppose I have two tables. How can I find if the two have "identical rows"; in the sense that they are allowed to have different primary keys but in respect to all the other fields they are the same.
You need to join those two tables and search rows where all wanted columns have similar values. Something like this:
select table1.id as table1_id, table2.id as table2_id from table1,table2 where table1.column1 = table2.column1 and table1.column2 = table2.column2 and table1.column3 = table2.column3;
Be aware that this can return the same id values multiple times if you got multiple duplicates.
Geoff Jones wrote: i.e. I'm a little puzzed by the "table1.id as table1_id" (the last bit)
Is table1.id the primary key of table1? What is table1_id?
table1_id is just a alias for the id in table1. And the example assumed
that you have a table named table1 and table2 and both have column named
id as their primary key. Without the alias, your query would return just
two columns, both named as "id", so it would be harder for you to know
which id belongs to which table.
The name of alias is not much ruled, so you could say:
select
table1.id as cat,
table2.id as dog
And it would be as valid and working. But I like naming the aliases so
that you know the table and column from the name.
Thanks Aggro
"Aggro" <sp**********@y ahoo.com> wrote in message
news:wj******** *******@read3.i net.fi... Geoff Jones wrote:
i.e. I'm a little puzzed by the "table1.id as table1_id" (the last bit)
Is table1.id the primary key of table1? What is table1_id?
table1_id is just a alias for the id in table1. And the example assumed that you have a table named table1 and table2 and both have column named id as their primary key. Without the alias, your query would return just two columns, both named as "id", so it would be harder for you to know which id belongs to which table.
The name of alias is not much ruled, so you could say: select table1.id as cat, table2.id as dog
And it would be as valid and working. But I like naming the aliases so that you know the table and column from the name. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: phillip.s.powell |
last post by:
MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't
ask)
I have database Spring with table Students
I have database Summer with table Students
I am tasked to produce a query of all students in both tables with no
duplicates. No clue whatsoever.
|
by: Neo Geshel |
last post by:
I am having conflicting results with two pieces of identical code. One
is an insert, the other is an update to a db.
The first code, which works, is this:
Sub Add3_Click(sender As Object, e As EventArgs)
Dim imgStream as Stream = Add3Image.PostedFile.InputStream
Dim imgLen as Integer = Add3Image.PostedFile.ContentLength
Dim imgType as String = Add3Image.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType =
|
by: Thanya Teutschbeim |
last post by:
I'm trying to use DataSet.Merge, but it works like an Append, and I don't
want this. I want to update dataset data.
I have two files with same fields and the same xml schema. For example:
File 1:
<?xml version="1.0" standalone="yes" ?>
<Traducao xmlns="http://www.tempuri.org/traducao.xsd">
<comp formulario="Form1" componente="btnOk" traducao="" id="-1">
<item>0</item>
|
by: Brian Tabios |
last post by:
Hello Everyone,
I have a very complex performance issue with our production database.
Here's the scenario. We have a production webserver server and a
development web server. Both are running SQL Server 2000.
I encounted various performance issues with the production server with a
particular query. It would take approximately 22 seconds to return 100
rows, thats about 0.22 seconds per row. Note: I ran the query in single
user mode. So...
|
by: BTabios |
last post by:
Hello Everyone,
I have a very complex performance issue with our production database.
Here's the scenario. We have a production webserver server and a
development web server. Both are running SQL Server 2000.
I encounted various performance issues with the production server with
a particular query. It would take approximately 22 seconds to return
100 rows, thats about 0.22 seconds per row. Note: I ran the query in
single user mode. So...
| |
by: inpuarg |
last post by:
I have 2 datatables. They are identical. I want to compare them by
cell's content. They are all same.
But dt1 == dt2 or
dt1.GetHashCode() == dt2.GetHashCode() doesn 't work.
There are big amount of rows in theese datatables . So i don 't want
to enumerate each rows. This is not efficient and unacceptable for my
current application.
|
by: war_wheelan |
last post by:
I am replicating an 80GB database between NY can CT and would like to
know why table sizes are different between the two.
Here is an example of sp_spaceused::
NY IOI_2007_04_23 rows(279,664) reserved(464,832)
data(439,960) index_size(24,624)
CT IOI_2007_04_23 rows(279,666) reserved(542,232)
data(493,232) index_size(48,784)
Thanks,
|
by: rshivaraman |
last post by:
CREATE TABLE (
(10)
NULL
)
CREATE TABLE (
(10)
NULL
)
|
by: ago |
last post by:
Hi,
I have an access query that finds the rows that have certain parameters common among them eg : Username
How is it possible to highlight the matches or display only the matches.
TBL:
username age school city
jon 11 a b
jon 12 c d
jane 13 e f
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: 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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |