PC Review


Reply
Thread Tools Rate Thread

Comparing two values in different rows of a table

 
 
Rex
Guest
Posts: n/a
 
      17th Jan 2007
Hi,

I want to compare data in two different rows of a table. For eg. I have
a table called twins and each twin has a unique individual ID, for
instance twinA (first born twin) has an ID: 2 whereas twinB (second
born twin) has an ID: 3. both of these records belong to a particular
familyID.

Now I want to be able to compare if sex of both the twins are same or
different

The original table looks something like this:

FamilyID | individual_ID | Name | Sex
---------------------------------------------------------
000 | 02 | john | male
000 | 03 | kasey | female
222 | 02 | jack | male
222 | 03 | ryan | male

I want to have a calculated field which would look at the sex of each
twin belonging to a particular family and tell me where they are same
sex or not. so the new query would look something like this:

FamilyID | individual_ID | Name | Sex | sameSex
--------------------------------------------------------------------------------
000 | 02 | john | male | No
000 | 03 | kasey | female | No
222 | 02 | jack | male | Yes
222 | 03 | ryan | male | Yes

Thanks
Rex

 
Reply With Quote
 
 
 
 
Bill Edwards
Guest
Posts: n/a
 
      17th Jan 2007
SELECT tblTwin.FamilyId, tblTwin.IndividualId,
tblTwin.Name, tblTwin.Sex, tblTwin_1.Name,
tblTwin_1.Sex, tblTwin_1.IndividualId,
IIf(TblTwin.sex=tbltwin_1.sex,"Same","Different") AS Expr1
FROM tblTwin INNER JOIN tblTwin AS tblTwin_1
ON tblTwin.FamilyId = tblTwin_1.FamilyId
WHERE (((tblTwin.IndividualId)<>[tblTwin_1].[IndividualId]));

"Rex" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I want to compare data in two different rows of a table. For eg. I have
> a table called twins and each twin has a unique individual ID, for
> instance twinA (first born twin) has an ID: 2 whereas twinB (second
> born twin) has an ID: 3. both of these records belong to a particular
> familyID.
>
> Now I want to be able to compare if sex of both the twins are same or
> different
>
> The original table looks something like this:
>
> FamilyID | individual_ID | Name | Sex
> ---------------------------------------------------------
> 000 | 02 | john | male
> 000 | 03 | kasey | female
> 222 | 02 | jack | male
> 222 | 03 | ryan | male
>
> I want to have a calculated field which would look at the sex of each
> twin belonging to a particular family and tell me where they are same
> sex or not. so the new query would look something like this:
>
> FamilyID | individual_ID | Name | Sex | sameSex
> --------------------------------------------------------------------------------
> 000 | 02 | john | male | No
> 000 | 03 | kasey | female | No
> 222 | 02 | jack | male | Yes
> 222 | 03 | ryan | male | Yes
>
> Thanks
> Rex
>



 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      17th Jan 2007
Bill, the query you have written does not work unfortunately.. Also why
do you have tblTwin_1. This is a bit of concern to me as there is only
one table "twins".


Bill Edwards wrote:
> SELECT tblTwin.FamilyId, tblTwin.IndividualId,
> tblTwin.Name, tblTwin.Sex, tblTwin_1.Name,
> tblTwin_1.Sex, tblTwin_1.IndividualId,
> IIf(TblTwin.sex=tbltwin_1.sex,"Same","Different") AS Expr1
> FROM tblTwin INNER JOIN tblTwin AS tblTwin_1
> ON tblTwin.FamilyId = tblTwin_1.FamilyId
> WHERE (((tblTwin.IndividualId)<>[tblTwin_1].[IndividualId]));
>
> "Rex" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I want to compare data in two different rows of a table. For eg. I have
> > a table called twins and each twin has a unique individual ID, for
> > instance twinA (first born twin) has an ID: 2 whereas twinB (second
> > born twin) has an ID: 3. both of these records belong to a particular
> > familyID.
> >
> > Now I want to be able to compare if sex of both the twins are same or
> > different
> >
> > The original table looks something like this:
> >
> > FamilyID | individual_ID | Name | Sex
> > ---------------------------------------------------------
> > 000 | 02 | john | male
> > 000 | 03 | kasey | female
> > 222 | 02 | jack | male
> > 222 | 03 | ryan | male
> >
> > I want to have a calculated field which would look at the sex of each
> > twin belonging to a particular family and tell me where they are same
> > sex or not. so the new query would look something like this:
> >
> > FamilyID | individual_ID | Name | Sex | sameSex
> > --------------------------------------------------------------------------------
> > 000 | 02 | john | male | No
> > 000 | 03 | kasey | female | No
> > 222 | 02 | jack | male | Yes
> > 222 | 03 | ryan | male | Yes
> >
> > Thanks
> > Rex
> >


 
Reply With Quote
 
Van T. Dinh
Guest
Posts: n/a
 
      17th Jan 2007
Need a bit more clarifications:

1. How do you distinguish the multiple sets of twins if a family has more
than 1 set of twins?

2. Any triplet or quad in your database?

--
HTH
Van T. Dinh
MVP (Access)



"Rex" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I want to compare data in two different rows of a table. For eg. I have
> a table called twins and each twin has a unique individual ID, for
> instance twinA (first born twin) has an ID: 2 whereas twinB (second
> born twin) has an ID: 3. both of these records belong to a particular
> familyID.
>
> Now I want to be able to compare if sex of both the twins are same or
> different
>
> The original table looks something like this:
>
> FamilyID | individual_ID | Name | Sex
> ---------------------------------------------------------
> 000 | 02 | john | male
> 000 | 03 | kasey | female
> 222 | 02 | jack | male
> 222 | 03 | ryan | male
>
> I want to have a calculated field which would look at the sex of each
> twin belonging to a particular family and tell me where they are same
> sex or not. so the new query would look something like this:
>
> FamilyID | individual_ID | Name | Sex | sameSex
> --------------------------------------------------------------------------------
> 000 | 02 | john | male | No
> 000 | 03 | kasey | female | No
> 222 | 02 | jack | male | Yes
> 222 | 03 | ryan | male | Yes
>
> Thanks
> Rex
>



 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      17th Jan 2007
each individual is recognized based on the individual ID so first set
of twins is given individual ID as 2 and 3 second set of twins have
individual IDs 7 and 8, first set of triplets have individual IDs as 4,
5, 6. Database does not include second set of triplets. It also does
not include quads..


Van T. Dinh wrote:
> Need a bit more clarifications:
>
> 1. How do you distinguish the multiple sets of twins if a family has more
> than 1 set of twins?
>
> 2. Any triplet or quad in your database?
>
> --
> HTH
> Van T. Dinh
> MVP (Access)
>
>
>
> "Rex" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I want to compare data in two different rows of a table. For eg. I have
> > a table called twins and each twin has a unique individual ID, for
> > instance twinA (first born twin) has an ID: 2 whereas twinB (second
> > born twin) has an ID: 3. both of these records belong to a particular
> > familyID.
> >
> > Now I want to be able to compare if sex of both the twins are same or
> > different
> >
> > The original table looks something like this:
> >
> > FamilyID | individual_ID | Name | Sex
> > ---------------------------------------------------------
> > 000 | 02 | john | male
> > 000 | 03 | kasey | female
> > 222 | 02 | jack | male
> > 222 | 03 | ryan | male
> >
> > I want to have a calculated field which would look at the sex of each
> > twin belonging to a particular family and tell me where they are same
> > sex or not. so the new query would look something like this:
> >
> > FamilyID | individual_ID | Name | Sex | sameSex
> > --------------------------------------------------------------------------------
> > 000 | 02 | john | male | No
> > 000 | 03 | kasey | female | No
> > 222 | 02 | jack | male | Yes
> > 222 | 03 | ryan | male | Yes
> >
> > Thanks
> > Rex
> >


 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      17th Jan 2007
I know the database design is very poor.. but I cant change the design
as lot of data has already been entered in the tables..

Rex

Rex wrote:
> each individual is recognized based on the individual ID so first set
> of twins is given individual ID as 2 and 3 second set of twins have
> individual IDs 7 and 8, first set of triplets have individual IDs as 4,
> 5, 6. Database does not include second set of triplets. It also does
> not include quads..
>
>
> Van T. Dinh wrote:
> > Need a bit more clarifications:
> >
> > 1. How do you distinguish the multiple sets of twins if a family has more
> > than 1 set of twins?
> >
> > 2. Any triplet or quad in your database?
> >
> > --
> > HTH
> > Van T. Dinh
> > MVP (Access)
> >
> >
> >
> > "Rex" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi,
> > >
> > > I want to compare data in two different rows of a table. For eg. I have
> > > a table called twins and each twin has a unique individual ID, for
> > > instance twinA (first born twin) has an ID: 2 whereas twinB (second
> > > born twin) has an ID: 3. both of these records belong to a particular
> > > familyID.
> > >
> > > Now I want to be able to compare if sex of both the twins are same or
> > > different
> > >
> > > The original table looks something like this:
> > >
> > > FamilyID | individual_ID | Name | Sex
> > > ---------------------------------------------------------
> > > 000 | 02 | john | male
> > > 000 | 03 | kasey | female
> > > 222 | 02 | jack | male
> > > 222 | 03 | ryan | male
> > >
> > > I want to have a calculated field which would look at the sex of each
> > > twin belonging to a particular family and tell me where they are same
> > > sex or not. so the new query would look something like this:
> > >
> > > FamilyID | individual_ID | Name | Sex | sameSex
> > > --------------------------------------------------------------------------------
> > > 000 | 02 | john | male | No
> > > 000 | 03 | kasey | female | No
> > > 222 | 02 | jack | male | Yes
> > > 222 | 03 | ryan | male | Yes
> > >
> > > Thanks
> > > Rex
> > >


 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      17th Jan 2007
Hi.. is there anyone who can solve this problem of mine..

Rex wrote:
> I know the database design is very poor.. but I cant change the design
> as lot of data has already been entered in the tables..
>
> Rex
>
> Rex wrote:
> > each individual is recognized based on the individual ID so first set
> > of twins is given individual ID as 2 and 3 second set of twins have
> > individual IDs 7 and 8, first set of triplets have individual IDs as 4,
> > 5, 6. Database does not include second set of triplets. It also does
> > not include quads..
> >
> >
> > Van T. Dinh wrote:
> > > Need a bit more clarifications:
> > >
> > > 1. How do you distinguish the multiple sets of twins if a family has more
> > > than 1 set of twins?
> > >
> > > 2. Any triplet or quad in your database?
> > >
> > > --
> > > HTH
> > > Van T. Dinh
> > > MVP (Access)
> > >
> > >
> > >
> > > "Rex" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Hi,
> > > >
> > > > I want to compare data in two different rows of a table. For eg. I have
> > > > a table called twins and each twin has a unique individual ID, for
> > > > instance twinA (first born twin) has an ID: 2 whereas twinB (second
> > > > born twin) has an ID: 3. both of these records belong to a particular
> > > > familyID.
> > > >
> > > > Now I want to be able to compare if sex of both the twins are same or
> > > > different
> > > >
> > > > The original table looks something like this:
> > > >
> > > > FamilyID | individual_ID | Name | Sex
> > > > ---------------------------------------------------------
> > > > 000 | 02 | john | male
> > > > 000 | 03 | kasey | female
> > > > 222 | 02 | jack | male
> > > > 222 | 03 | ryan | male
> > > >
> > > > I want to have a calculated field which would look at the sex of each
> > > > twin belonging to a particular family and tell me where they are same
> > > > sex or not. so the new query would look something like this:
> > > >
> > > > FamilyID | individual_ID | Name | Sex | sameSex
> > > > --------------------------------------------------------------------------------
> > > > 000 | 02 | john | male | No
> > > > 000 | 03 | kasey | female | No
> > > > 222 | 02 | jack | male | Yes
> > > > 222 | 03 | ryan | male | Yes
> > > >
> > > > Thanks
> > > > Rex
> > > >


 
Reply With Quote
 
Van T. Dinh
Guest
Posts: n/a
 
      17th Jan 2007
While it may be possible to fudge around with SQL to work out what you want,
you will encounter numerous problems later with the current Table structure
and it is much better to re-structure your Table(s) according to the
Relational Database Design Theory.

--
HTH
Van T. Dinh
MVP (Access)



"Rex" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi.. is there anyone who can solve this problem of mine..
>



 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      17th Jan 2007
I know I need to change my table structures.. for which we are
designing a new database from scrach..

For the time being is it possible for you to give me the solution of my
problem. Also where can I read about Relational Database Design Theory

cheers
Van T. Dinh wrote:
> While it may be possible to fudge around with SQL to work out what you want,
> you will encounter numerous problems later with the current Table structure
> and it is much better to re-structure your Table(s) according to the
> Relational Database Design Theory.
>
> --
> HTH
> Van T. Dinh
> MVP (Access)
>
>
>
> "Rex" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi.. is there anyone who can solve this problem of mine..
> >


 
Reply With Quote
 
Van T. Dinh
Guest
Posts: n/a
 
      18th Jan 2007
See the Microsoft Knowledge Base article:

http://support.microsoft.com/kb/283698

Forget about trying to work with current structure. I tried to do a quick
sample SQL but it is simply too messy so I gave up.

--
HTH
Van T. Dinh
MVP (Access)



"Rex" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I know I need to change my table structures.. for which we are
> designing a new database from scrach..
>
> For the time being is it possible for you to give me the solution of my
> problem. Also where can I read about Relational Database Design Theory
>
> cheers



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing data in mult rows then summing unique values Cathy Landry Microsoft Excel Misc 2 17th Mar 2009 11:27 PM
Comparing Values in Separate Rows in Access homerj0216 Microsoft Access VBA Modules 4 28th Mar 2008 04:50 PM
Macro Help Needed: Comparing cell values and deleting rows clint.sylvestre@gmail.com Microsoft Excel Misc 1 19th Sep 2006 02:39 AM
Comparing Rows in a Table =?Utf-8?B?aW1jcGhlcnM=?= Microsoft Access 1 7th Sep 2005 06:06 AM
Comparing two rows and finding values in one row not in the other. Malkial Microsoft Excel Misc 0 23rd Jun 2004 01:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:16 AM.