Re: find differences between two mysql_query results. HELP
- From: Erwin Moller <since_humans_read_this_I_am_spammed_too_much@xxxxxxxxxxxxxxxx>
- Date: Mon, 29 May 2006 14:29:54 +0200
mharmon827@xxxxxxxxx wrote:
When I type an agentnum and hit submit at will look up that agentnum
and tell you what skill set (msp_sk,ste_sk,wash_sk,ectect) they are not
a part of.
For Example
the first statement I have been ussing is this. it Tells me what they
DO have.
SELECT queue FROM agentqueue_table WHERE agentnum='12345' GROUP BY
queue;
The result is
+-----------+
| queue |
+-----------+
| msp_sk |
| ste_sk |
+------------+
The second statment is, it tells me what all the skill sets are.
SELECT queue FROM agentqueue_table GROUP BY queue;
+-------------+
| queue |
+-------------+
| msp_sk |
| ste_sk |
| wash_sk |
+-------------+
I want to compare the two results and know the difference is wash_sk
I need to do this dynamicly as well. Lets say I do another agentnum
lookup with agent 54321 and his results are as followed
+-----------+
| queue |
+-----------+
| msp_sk |
| wash_sk |
+------------+
and compare it to again,
SELECT queue FROM agentqueue_table GROUP BY queue;
+-------------+
| queue |
+-------------+
| msp_sk |
| ste_sk |
| wash_sk |
+-------------+
The answer I want to get then is ste_sk
If I am going about this all wrong please let me know!
I have spent all day trying to find a way to do this and i can't! I am
going nuts... Please help!
Hi,
You can solve this in SQL or in PHP, but I suggest you try SQL.
First, you are using GROUP BY in a way that tells me you don't know what it
is for. Use GROUP BY to group aggregates, but you didn't define any in your
query.
I think you need DISTINCT instead of this strange use of GROUP BY.
Read up here: www.w3schools.com and select SQL.
Also, next time tell us how the table looks. :-)
If you want all different rows in agentqueue_table that a certain agentnum
doesn't have, try something along these lines:
suppose a table like:
CREATE TABLE agentqueue_table(
agentnum integer,
queue text
)
and you want all queue that:
1) exists in the table
2) are not 'linked' already to the agentnum
try something like this:
SELECT DISTINCT AG1.queue FROM agentqueue_table AS AG1
WHERE(
AG1.queue NOT IN
(SELECT DISTINCT AG2.queue FROM agentqueue_table AS AG2 WHERE
(AG2.agentnum='12345') )
)
[not tested, just an example to help you going]
Or have a look at functions like UNION, INTERSECTS, etc, which are probably
more efficient than my example if used right.
Hope that helps.
Regards,
Erwin Moller
.
- Follow-Ups:
- Re: find differences between two mysql_query results. HELP
- From: mharmon827@xxxxxxxxx
- Re: find differences between two mysql_query results. HELP
- References:
- find differences between two mysql_query results. HELP
- From: mharmon827@xxxxxxxxx
- find differences between two mysql_query results. HELP
- Prev by Date: Re: calculating complete quarters between two dates
- Next by Date: Re: How do I download and edit a website?
- Previous by thread: find differences between two mysql_query results. HELP
- Next by thread: Re: find differences between two mysql_query results. HELP
- Index(es):