Yes, the name clauses will apply to the second select only. I'm assuming you are using SQL Server here, but I guess it would be similar for Access.
There are two ways you can do this: put the (and name = 'xyz' and last_name = 'xyz') into each select statement as I'm sure you've already worked out, or get everything and then apply the where.
Note that the first option is probably more efficient, as you won't be a load of rows and then throwing most of them away.
To do the second way as you are asking, you will need to do all the unions as a sub-query then do a select and where name.. around it. Something like this should do it:
SQL Code:
SELECT CompanyID, CompanyName FROM
(
SELECT supplier_id AS CompanyID, supplier_name AS CompanyName, [name], last_name
FROM suppliers
WHERE supplier_id > 2000
UNION
SELECT company_id AS CompanyID, company_name AS CompanyName, [name], last_name
FROM companies
WHERE company_id > 1000
) thesubquery
WHERE
name = 'xyz' AND last_name = 'xyz'
ORDER BY CompanyName;
The main things to note here are:
1. We put the whole of the UNION query in brackets and give it a name of thesubquery. This lets us use it as if there were a normal table called thesubquery.
2. Along with the IDs and names the UNION query also needs to return the things we will filter on, name and last_name, otherwise these won't be available in the final where clause.
3. I gave the supplier_id/company_id and supplier_name/company_name columns aliases of CompanyID and CompanyName, to make it a little more obvious how to reference them outside the subquery.
Hope this makes sense.
Phil