Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to write a query to pull data matching 2 tables and2 variables 1

Status
Not open for further replies.

teamssc

Instructor
Nov 16, 2000
65
US
I'm fairly new using SQL Queries. The query below works fine until I add the last line "and mail6.folder like 'X-GM%'". I'm guessing that I'm not using "and" correctly and thus it is not seeing the additional variable. Any help would be appreciated. Thanks!


select *
from gm6.dbo.mailbox as mail6
left join goldmine8.dbo.mailbox as mail8
on (coalesce(mail6.recid,'') <> coalesce(mail8.recid, ' '))
and mail6.folder like 'X-GM%'
 
You JOIN table with LEFT join. That means you will have ALL records from Mail6 and only matching records from Mail8.
If you join tables like you do that means you want want ONLY these records from Mail8 which have different RecId from Mail6 BUT Only for these records from Mail6 which starts with X-GM. If you want to filter your records to get only X-GM started records you must use WHERE clause:
Code:
select * 
       from gm6.dbo.mailbox as mail6
left join goldmine8.dbo.mailbox as mail8
on (coalesce(mail6.recid,'') <> coalesce(mail8.recid, ' '))
WHERE mail6.folder like 'X-GM%'




Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top