473,385 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

INTERSECT alternative in MySQL

Hello everyone, I am new to MySQL but just realized it does not support INTERSECT in MySQL 5.0 Community Server.

I have this problem to solve.
(1) cust_table
cust_id
city_code.

(2) agent_table
agent_code
cust_id

An agent may work for more than one customer.

My idea was to have two tables and use INTERSECT to produce a result that would list all agents that serve all customers in a particular city grouped by cities.

SELECT cust_id FROM cust_table where city_code IN (city1, city2)
INTERSECT
SELECT cust_id FROM agent_table;

But MySQL does not have INTERSECT so I am confused as to the solution.
Apr 10 '07 #1
2 4918
code green
1,726 Expert 1GB
Can't promise this is exactly what you want but should point you in right direction.
Expand|Select|Wrap|Line Numbers
  1. SELECT agent_code,city_code FROM cust_table 
  2. JOIN agent_table USING (cust_id)
  3. GROUP BY city_code
Apr 11 '07 #2
Thanks for the effort. The final query I got that did the job was so convoluted, I am still trying to understand it. ;-)

And sorry for the bother and not providing enough details.
I was basically looking for an alternative to the INTERSECT which is absent from MySQL implementatios.

SELECT DISTINCT a.aid, a.percent
FROM agent a
WHERE (SELECT COUNT(DISTINCT(o.cid))
FROM order1 o, customer c2
WHERE o.aid=a.aid
AND c2.cid=o.cid
AND c2.city='Dallas') = (SELECT COUNT(*)
FROM customer c
WHERE c.city='Dallas')
ORDER BY a.percent DESC;
Apr 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Nick | last post by:
I have three tables books (id, title, author) authors (id, name) authors_groups (author_id, group_id) I have a query that searches for authors who must be in a least one subgroup of two...
1
by: sunaina | last post by:
I am doing the following query using intersect but gives me an error 'error in sql syntax. I tried using join as well but gives me similar error. In the following code still has intersect just to...
1
by: Xpertboy | last post by:
i am trying to execute following code in asp var strSQL1="select Model from Phones where Brand='"+ brand +"'"; var strSQL2="select Model from Phones where Model='"+ model +"'"; var...
3
by: prathamesh.deshpande | last post by:
Hi, I am facing problem while excuting a mysql query. My problem is as follows- I have two tables object_1 and object_2. The structure of object_1 is object_id name address ------------...
3
by: bzb | last post by:
hi ALL, I have a situation to use INTERSECT in my query, but INTERSECT is not supported in "mysql 4.1.15". Can anyone explain me how to tackle this problem..... ! Also, is there...
0
by: egur | last post by:
Hi, I'm looking for reliable MySQL version (for Windows) that supports "EXCEPT" and "INTERSECT" execution. Would somebody recommend such version (and corresponding client), please?
1
by: maddamon | last post by:
My problem looks like that: SELECT * FROM `table` where `attribute` = '24' INTERSECT SELECT * FROM `table` where `attribute` = '16'; and my 'table' structure is :...
1
by: kadhir34 | last post by:
Can any one give an alternative to this oracle query in mysql Select s.EMP_CODE,fname from profilesys.skill_emp_master P join profilesys.skill_master_new R on ( P.Skill_id = r.skill_id) join...
1
by: b00010783 | last post by:
Hi all, I have the table below. +--------+---------+-------------+--------------------------------+-------+----+ | parent | country | city | hotel | stars | id | ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.