Page 1 of 1

question about two table

Posted: Thu Oct 12, 2006 5:58 am
by wong0630
Assume there are two tables which are member message

member table
email name
abc@abc.com abc
def@def.com def
ghi@ghi.com ghi

message table
serial no sender_id receiver_id
1 abc@abc.com def@def.com
2 abc@abc.com ghi@ghi.com


Now, client will input sender email (eg: abc@abc.com), system need to display all information from message table which sender_id is abc@abc.com


Let's say the result should be
sender email sender name receiver email receiver name
abc@abc.com abc def@def.com def
abc@abc.com abc ghi@ghi.com ghi


What is the sql code if I need the above result? Thanks very much.

Posted: Thu Oct 12, 2006 6:13 am
by impulse()
Excuse me for not understanding 100% what you mean. But I think I have a fair idea. If you want to join tables then use the following code:

Code: Select all

SELECT 
            t1.column1, t2.column1, t2.column2, t2.column3
FROM   
            table1 as t1
LEFT JOIN
            table2 as t2
ON
            t1.whatYouWantToJoin = t2.whatYouWantToJoin
On that example I'm selecting column1 from table 1 (t1.column1) etc etc

And then joining then where whatYouWantToJoin from table 1 is equal to whatYouWantToJoin from table 2

Hope that helps,

Stephen,