dennisdominic
asked on
Extract emails based on domain on another table.
DB: Access 2002.
I only have two simple tables.
Table A
- email [string]
Table B
- domain [string]
-------------------------- --------
Table A Sample Data
- abc@hotmail.com
- abc@NotThisDomain.com
- abc@yahoo.com
- abc@NotThisToo.com
- abc@yahoo.com.au
-------------------------- --------
Table B Sample Data
- hotmail.com
- yahoo.com
-------------------------- --------
I want a method (Query or function call to create new table) to extract the listed Domains in Table B out from Table A.
Wanted Result Table
- abc@hotmail.com
- abc@yahoo.com
- abc@yahoo.com.au
I only have two simple tables.
Table A
- email [string]
Table B
- domain [string]
--------------------------
Table A Sample Data
- abc@hotmail.com
- abc@NotThisDomain.com
- abc@yahoo.com
- abc@NotThisToo.com
- abc@yahoo.com.au
--------------------------
Table B Sample Data
- hotmail.com
- yahoo.com
--------------------------
I want a method (Query or function call to create new table) to extract the listed Domains in Table B out from Table A.
Wanted Result Table
- abc@hotmail.com
- abc@yahoo.com
- abc@yahoo.com.au
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
On my own table.... Method from peter57r returns 81 rows and method from Rimvis returns 259 rows.
My own ASP Script below returns 399 rows.
<%
set rs1 = conn.execute("Select Domain from TableB")
while not rs1.eof
sqlstr = "select email from TableA where email like '%@%" & rs1("Domain") & "%'"
set rs2 = conn.execute(sqlstr)
while not rs2.eof
sqlstr="Insert INTO ResultTable (newEmail) values ('" & rs2("email") & "')"
conn.execute(sqlstr)
rs2.movenext
wend
rs1.movenext
wend
%>
Ther's an erros in your script
'%@%" & rs1("Domain") & "%'" - extra '%' after @
Should be
'%@" & rs1("Domain") & "%'" - extra '%' after @
'%@%" & rs1("Domain") & "%'" - extra '%' after @
Should be
'%@" & rs1("Domain") & "%'" - extra '%' after @
Oops
Should be
'%@" & rs1("Domain") & "%'"
Should be
'%@" & rs1("Domain") & "%'"
ASKER
I can email the entire database (10mb) to you if you drop me an email at dennisdominc @ gmail . com
Hoping for a quick and dirty SQL solution that I can implement on Query
or any ACCESS solution.
Hoping for a quick and dirty SQL solution that I can implement on Query
or any ACCESS solution.
Check result with your corrected script.
This should work:
SELECT A.email
FROM A INNER JOIN B ON A.email LIKE ('%@' + B.domain + '%');
BTW, question related communication via e-mail is against Member Agreement
This should work:
SELECT A.email
FROM A INNER JOIN B ON A.email LIKE ('%@' + B.domain + '%');
BTW, question related communication via e-mail is against Member Agreement
ASKER
'%@" & rs1("Domain") & "%'"
- 259... Cool... you are right. :-)
'%@%" & rs1("Domain") & "%'"
- 399 rows... I was hoping to capture those abc@uk.yahoo.com abc@yahoo.com.uk and all variations..
- 259... Cool... you are right. :-)
'%@%" & rs1("Domain") & "%'"
- 399 rows... I was hoping to capture those abc@uk.yahoo.com abc@yahoo.com.uk and all variations..
>> I was hoping to capture those abc@uk.yahoo.com abc@yahoo.com.uk and all variations
Last % DOES it.
Last % DOES it.
ASKER
you need to fit a % (or *) between @ and yahoo.com for uk. to go in...
don't email me :-p I didn't realise the rules.
don't email me :-p I didn't realise the rules.
Sorry, didn't got it, I was thinking about yahoo.com.uk.
In this case, you ARE right. Should be
SELECT A.email
FROM A INNER JOIN B ON A.email LIKE ('%@%' + B.domain + '%');
In this case, you ARE right. Should be
SELECT A.email
FROM A INNER JOIN B ON A.email LIKE ('%@%' + B.domain + '%');
Select * from tableA
Where mid([email], instr([email],"@")+1) in (Select Domain from tableB)
Pete