|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
Select From Two Tables
I apologise if this has been answered before _ I did search but didn't find anything.
basically I have two tables, temp_list and mailing_list Both tables have a field called 'email' which stores an email address. On sign up to the mailing list, I need to be able to check whether the email address being signed up exists in [b]either[b]table (it woun't exist in both unless something ahs gone terribly wrong). I have tried something like this: SELECT * FROM mailing_list, temp_list WHERE mailing_list.email OR temp_list.email = "email@to.search.for" and loads of other similar things. The above query, helpfully returns all rows in both tables. I have trawled though all the relevant documentation and help forums I can think of and learnt lots of interesting and complex things about JOIN e.t.c but I can't seem to solve this very simple problem. Or is the solution to use two seperate SELECT statements UNIONed together? Thanks for any help. Paul
__________________
|
|
#2
|
||||
|
||||
|
Code:
select 'M', email from mailing_list where email = 'email@to.search.for' union all select 'T', email from temp_list where email = 'email@to.search.for' |
|
#3
|
||||
|
||||
|
Yeah I thought of that just as I was finishing my above post.
I thought I would as to see if there was a better way anyway. Cheers mate. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Select From Two Tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|