infinitizon
MIS
Ok, I understand the title may not speak exactly what I want to achieve and this may also not be the right forum for it.
If my guess above is right, please help me redirect as appropriate.
Well, here's an issue I've been trying to work around on MySql (No problem if you are better with MSSQL. I understand the both).
I have a table called members (I use it to store registered members) like so:
Another table called comtacts like so
Finally, there is a table that links the two tables called buyers_bought like so
Now, when I run this query against the database
I get this result duplicate result for contacts that has been bought by more than one member.
So suppose I want to get all contacts when brown logs in, I get something like
The challenge is if b@c.com is the currently logged on user, it should give a result similar to the following
If my guess above is right, please help me redirect as appropriate.
Well, here's an issue I've been trying to work around on MySql (No problem if you are better with MSSQL. I understand the both).
I have a table called members (I use it to store registered members) like so:
Code:
member_id | createDate | first_name | last_name | street | state | country | phone | email |
1 | 2012-06-09 | James | Ini | xxx | xxxx | U.S.A | xxx | a@y.com |
2 | 2012-06-10 | Brown | Tony | xxx | xxxx | U.S.A | xxx | b@c.com |
Code:
contact_id | contact_name | contact_addr | contacts_country | contact_phone | contact_email
1 | Pats Ltd. | N.J | U.S.A | xxxxxx | k@g.com
2 | West minister | N.Y. | U.S.A | xxxxxx | y@z.com
3 | infinitizon | Calif | U.S.A | xxxxxx | j@m.com
Code:
id | contacts_id | member_id | buyers_bought_date |
1 | 1 | 1 | 2012-06-09 |
2 | 2 | 1 | 2012-06-10 |
3 | 2 | 2 | 2012-06-11 |
Now, when I run this query against the database
Code:
SELECT contacts.contact_id, buyers_bought.contacts_id, contacts.contact_name,
(SELECT email FROM members WHERE member_id = buyers_bought.member_id) AS mem_email
, contacts.contact_addr, contacts.contacts_country, contacts.contact_phone
, contacts.contact_email
FROM contacts
LEFT JOIN buyers_bought
ON contacts.contact_id = buyers_bought.contacts_id
So suppose I want to get all contacts when brown logs in, I get something like
Code:
contact_id | contacts_id | contact_name | mem_email | contact_addr | contacts_country | contact_phone | contact_email
1 | 1 | Pats Ltd. | a@y.com | N.J | U.S.A. | xxxx | k@g.com
2 | 2 | West minister | a@y.com | N.Y. | U.S.A. | xxxx | y@z.com
2 | 2 | West minister | b@c.com | N.Y. | U.S.A. | xxxx | y@z.com
3 | NULL | infinitizon | NULL | Calif | U.S.A | xxxxxx | j@m.com
Code:
contact_id | contacts_id | contact_name | mem_email | contact_addr | contacts_country | contact_phone | contact_email
1 | 1 | Pats Ltd. | NULL | N.J | U.S.A. | xxxx | k@g.com
2 | 2 | West minister | b@c.com | N.Y. | U.S.A. | xxxx | y@z.com
3 | NULL | infinitizon | NULL | Calif | U.S.A | xxxxxx | j@m.com
Can anyone help me work this out