Unix Technical Forum

how to write sql to map attributes in one table to attributes in another table?

This is a discussion on how to write sql to map attributes in one table to attributes in another table? within the MySQL forums, part of the Database Server Software category; --> I have two data tables. Table 1 Sender and Recipient - sender_email_address - recipient_email_address Table 2 Email_ID_Map -email_id -email_address ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:27 AM
Roy
 
Posts: n/a
Default how to write sql to map attributes in one table to attributes in another table?

I have two data tables.

Table 1
Sender and Recipient
- sender_email_address
- recipient_email_address

Table 2
Email_ID_Map
-email_id
-email_address

All the sender_email_address(es) and recipient_email_address(es) in
Table 1 can be found in Table 2.

How to write SQL to create a view such that all the email addresses in
Table 1 are replaced with their corresponding email ids?

Thanks
Roy

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:27 AM
strawberry
 
Posts: n/a
Default Re: how to write sql to map attributes in one table to attributes in another table?

On 4 Sep, 05:19, Roy <royl...@hotmail.com> wrote:
> I have two data tables.
>
> Table 1
> Sender and Recipient
> - sender_email_address
> - recipient_email_address
>
> Table 2
> Email_ID_Map
> -email_id
> -email_address
>
> All the sender_email_address(es) and recipient_email_address(es) in
> Table 1 can be found in Table 2.
>
> How to write SQL to create a view such that all the email addresses in
> Table 1 are replaced with their corresponding email ids?
>
> Thanks
> Roy


What have you got so far?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:27 AM
Roy
 
Posts: n/a
Default Re: how to write sql to map attributes in one table to attributes in another table?

On Sep 3, 11:48 pm, strawberry <zac.ca...@gmail.com> wrote:
> On 4 Sep, 05:19, Roy <royl...@hotmail.com> wrote:
>
>
>
>
>
> > I have two data tables.

>
> > Table 1
> > Sender and Recipient
> > - sender_email_address
> > - recipient_email_address

>
> > Table 2
> > Email_ID_Map
> > -email_id
> > -email_address

>
> > All the sender_email_address(es) and recipient_email_address(es) in
> > Table 1 can be found in Table 2.

>
> > How to write SQL to create a view such that all the email addresses in
> > Table 1 are replaced with their corresponding email ids?

>
> > Thanks
> > Roy

>
> What have you got so far?- Hide quoted text -
>
> - Show quoted text -


Nothing much yet.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:27 AM
Roy
 
Posts: n/a
Default Re: how to write sql to map attributes in one table to attributes in another table?

On Sep 4, 12:43 am, Roy <royl...@hotmail.com> wrote:
> On Sep 3, 11:48 pm, strawberry <zac.ca...@gmail.com> wrote:
>
>
>
>
>
> > On 4 Sep, 05:19, Roy <royl...@hotmail.com> wrote:

>
> > > I have two data tables.

>
> > > Table 1
> > > Sender and Recipient
> > > - sender_email_address
> > > - recipient_email_address

>
> > > Table 2
> > > Email_ID_Map
> > > -email_id
> > > -email_address

>
> > > All the sender_email_address(es) and recipient_email_address(es) in
> > > Table 1 can be found in Table 2.

>
> > > How to write SQL to create a view such that all the email addresses in
> > > Table 1 are replaced with their corresponding email ids?

>
> > > Thanks
> > > Roy

>
> > What have you got so far?- Hide quoted text -

>
> > - Show quoted text -

>
> Nothing much yet.- Hide quoted text -
>
> - Show quoted text -


OK, here is the solution.

create or replace view EMAIL_ALL as select a.sender_email_address,
b.email_id, a.recipient_email_address, c.email_id from
sender_and_recipient a, email_id_map b , email_id_map c where
a.sender_email_address = b.email_address and a.recipient_email_address
= c.email_address

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: how to write sql to map attributes in one table to attributes in another table?

On 4 Sep, 09:00, Roy <royl...@hotmail.com> wrote:
> On Sep 4, 12:43 am, Roy <royl...@hotmail.com> wrote:
>
>
>
>
>
> > On Sep 3, 11:48 pm, strawberry <zac.ca...@gmail.com> wrote:

>
> > > On 4 Sep, 05:19, Roy <royl...@hotmail.com> wrote:

>
> > > > I have two data tables.

>
> > > > Table 1
> > > > Sender and Recipient
> > > > - sender_email_address
> > > > - recipient_email_address

>
> > > > Table 2
> > > > Email_ID_Map
> > > > -email_id
> > > > -email_address

>
> > > > All the sender_email_address(es) and recipient_email_address(es) in
> > > > Table 1 can be found in Table 2.

>
> > > > How to write SQL to create a view such that all the email addresses in
> > > > Table 1 are replaced with their corresponding email ids?

>
> > > > Thanks
> > > > Roy

>
> > > What have you got so far?- Hide quoted text -

>
> > > - Show quoted text -

>
> > Nothing much yet.- Hide quoted text -

>
> > - Show quoted text -

>
> OK, here is the solution.
>
> create or replace view EMAIL_ALL as select a.sender_email_address,
> b.email_id, a.recipient_email_address, c.email_id from
> sender_and_recipient a, email_id_map b , email_id_map c where
> a.sender_email_address = b.email_address and a.recipient_email_address
> = c.email_address- Hide quoted text -
>
> - Show quoted text -


Better to write as explicit JOINs with obvious JOIN criteria rather
than comma joins where the criteria for each join is clear, thus:

CREATE OR REPLACE VIEW `EMAIL_ALL` AS
SELECT
`a`.`sender_email_address`,
`b`.`email_id`,
`a`.`recipient_email_address`,
`c`.`email_id`
FROM `sender_and_recipient` `a`
JOIN `email_id_map` `b` ON `a`.`sender_email_address` =
`b`.`email_address`
JOIN `email_id_map` `c` ON `a`.`recipient_email_address` =
`c`.`email_address`




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:27 AM
Roy
 
Posts: n/a
Default Re: how to write sql to map attributes in one table to attributes in another table?

On Sep 4, 1:48 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 4 Sep, 09:00, Roy <royl...@hotmail.com> wrote:
>
>
>
>
>
> > On Sep 4, 12:43 am, Roy <royl...@hotmail.com> wrote:

>
> > > On Sep 3, 11:48 pm, strawberry <zac.ca...@gmail.com> wrote:

>
> > > > On 4 Sep, 05:19, Roy <royl...@hotmail.com> wrote:

>
> > > > > I have two data tables.

>
> > > > > Table 1
> > > > > Sender and Recipient
> > > > > - sender_email_address
> > > > > - recipient_email_address

>
> > > > > Table 2
> > > > > Email_ID_Map
> > > > > -email_id
> > > > > -email_address

>
> > > > > All the sender_email_address(es) and recipient_email_address(es) in
> > > > > Table 1 can be found in Table 2.

>
> > > > > How to write SQL to create a view such that all the email addresses in
> > > > > Table 1 are replaced with their corresponding email ids?

>
> > > > > Thanks
> > > > > Roy

>
> > > > What have you got so far?- Hide quoted text -

>
> > > > - Show quoted text -

>
> > > Nothing much yet.- Hide quoted text -

>
> > > - Show quoted text -

>
> > OK, here is the solution.

>
> > create or replace view EMAIL_ALL as select a.sender_email_address,
> > b.email_id, a.recipient_email_address, c.email_id from
> > sender_and_recipient a, email_id_map b , email_id_map c where
> > a.sender_email_address = b.email_address and a.recipient_email_address
> > = c.email_address- Hide quoted text -

>
> > - Show quoted text -

>
> Better to write as explicit JOINs with obvious JOIN criteria rather
> than comma joins where the criteria for each join is clear, thus:
>
> CREATE OR REPLACE VIEW `EMAIL_ALL` AS
> SELECT
> `a`.`sender_email_address`,
> `b`.`email_id`,
> `a`.`recipient_email_address`,
> `c`.`email_id`
> FROM `sender_and_recipient` `a`
> JOIN `email_id_map` `b` ON `a`.`sender_email_address` =
> `b`.`email_address`
> JOIN `email_id_map` `c` ON `a`.`recipient_email_address` =
> `c`.`email_address`- Hide quoted text -
>
> - Show quoted text -


Thank you very much.
Roy

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com