Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

identical rows

 
   Database Help (Home) -> mySQL RSS
Next:  which version on xp pro  
Author Message
Geoff Jones

External


Since: Feb 08, 2005
Posts: 3



(Msg. 1) Posted: Tue Feb 08, 2005 10:40 am
Post subject: identical rows
Archived from groups: mailing>database>mysql (more info?)

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

 >> Stay informed about: identical rows 
Back to top
Login to vote
Aggro

External


Since: Aug 28, 2003
Posts: 8



(Msg. 2) Posted: Tue Feb 08, 2005 10:40 am
Post subject: Re: identical rows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.

 >> Stay informed about: identical rows 
Back to top
Login to vote
Geoff Jones

External


Since: Feb 08, 2005
Posts: 3



(Msg. 3) Posted: Tue Feb 08, 2005 11:40 am
Post subject: Re: identical rows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" wrote in message

 > 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.
 >> Stay informed about: identical rows 
Back to top
Login to vote
Aggro

External


Since: Aug 28, 2003
Posts: 8



(Msg. 4) Posted: Tue Feb 08, 2005 11:40 am
Post subject: Re: identical rows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.
 >> Stay informed about: identical rows 
Back to top
Login to vote
Geoff Jones

External


Since: Feb 08, 2005
Posts: 3



(Msg. 5) Posted: Tue Feb 08, 2005 4:40 pm
Post subject: Re: identical rows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks Aggro

"Aggro" wrote in message

 > 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.
 >> Stay informed about: identical rows 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Best way to issue hundreds of inserts/updates??? - Using mysql 4.0.23- What is the best way to execute several (hundreds of) inserts and updates? Rather than issuing tons of individual inserts and updates, can I send the strings to a text file and then have mysql do them all?? IE : query.txt insert..

MySQL freezes, brings XP machine to a grinding halt - I've been using MySQL for a while for fairly light database development on my XP machine. Currently, I am just starting a new project and have experienced some big problems with MySQL today both on my office machine and at home where running a particular...

login as user 'root' but do not have root privlages and my.. - Hi gang: I'm experiencing a problem with MySQL -- I updated MySQL from version 4.1.0 to 4.1.10 and now when I login as root it doesn't show all the databases I should have access to, nor it doesn't recognize me being logged in as root (via..

FLUSH TABLES hangs if table is locked - Using FLUSH TABLES via the C query API mysql_query() hangs if the table is locked already. That is to say, nothing prevents me from running a LOCK TABLES twice; it won't tell me "it's already locked, don't try to run a FLUSH". Anyone know ...

Tool to convert DDL in graphical diagram? - Does anyone know of a tool that will create a graphical diagram from a DDL (SQL create script)? Preferable a free open-source tool. Thanks, A
   Database Help (Home) -> mySQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]