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 Database forums, part of the Database Forums 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 All the sender_email_address(...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-04-2007
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

Reply With Quote
  #2 (permalink)  
Old 09-04-2007
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?

Reply With Quote
  #3 (permalink)  
Old 09-04-2007
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.

Reply With Quote
  #4 (permalink)  
Old 09-04-2007
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

Reply With Quote
  #5 (permalink)  
Old 09-04-2007
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`




Reply With Quote
  #6 (permalink)  
Old 09-04-2007
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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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



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


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0