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.
question about two table
Moderator: General Moderators
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
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:
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,
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.whatYouWantToJoinAnd then joining then where whatYouWantToJoin from table 1 is equal to whatYouWantToJoin from table 2
Hope that helps,
Stephen,