Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 retrive the value form two table

Author  Topic 

suguna
Starting Member

6 Posts

Posted - 2009-07-25 : 02:43:36
Hi all

I need a simple query,that to retrive the email from two table,if my email is existing in either one of the table.it should check in both the table,

for eg:
Table1:
name email
nirmala nirmala@gmail.com
suguan suguna@gmail.com


Table:2
name email
dhina dhina@gmail.com
sambath sambath@gmail.com

I need as
select * from table1 ,table2 where email='nirmala@gmail.com'


If any one knows,Please Help

Thanks in advance
Suguna






ss

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-07-25 : 03:02:12
Here the Query

select case when t1. email is null then t2. email else t1. email end as name
from temp1 t1 left outer join temp2 t2
on t1.name=t2.name
where t1.name = 'aaaa'

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-07-25 : 03:05:38
If your where clause is email then you use this

simple one


select email from temp1 where email='nirmala@gmail.com' union
select email from temp2 where email='nirmala@gmail.com'

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

suguna
Starting Member

6 Posts

Posted - 2009-07-25 : 03:10:14
Thank you Senthil,

But i didnt get the query,

since I didnt have common field for both the table,thats the difficult


Please Help
Go to Top of Page

suguna
Starting Member

6 Posts

Posted - 2009-07-25 : 03:12:59
Thanks you very much

Its worked

Thank you
Suguna
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-07-25 : 03:15:05
quote:
Originally posted by suguna

Thanks you very much

Its worked

Thank you
Suguna



Ya welcome.

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -