MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Tobias Asplund Date:November 3 2004 4:57pm
Subject:Re: INTERSECT in mysql
View as plain text  
On Wed, 3 Nov 2004, Chaitra Yale wrote:

> ...how can union be the same as intersect..iam trying to get the names
> of comapnies that are in both queries.....for example the first query
> gives me companies A, B AND C and the second query gives A , B..i want
> the intersect of these 2 queries....so i get companies A and B...if i
> did a union i will get A, B and C

Could use the union in a subquery together with a HAVING COUNT(*) on the
outside.

SELECT * FROM (
	SELECT DISTINCT col1 FROM t1 WHERE...
	UNION ALL
	SELECT DISTINCT col1 FROM t1 WHERE...
) AS tbl
GROUP BY tbl.col1 HAVING COUNT(*) = 2

Or something... not sure how well that would performe, however.
Thread
INTERSECT in mysqlChaitra Yale3 Nov
  • Re: INTERSECT in mysqlSGreen3 Nov
    • error with phpMyAdmin and MySQL 4.1.7DeRyl3 Nov
    • Re: INTERSECT in mysqlChaitra Yale3 Nov
      • Re: INTERSECT in mysqlMichael Stassen3 Nov
      • Re: INTERSECT in mysqlTobias Asplund3 Nov