CBWhiz
Looking For Status Send PM Posts: 1044
Threads: 130 Money: £1343.20 (D) (+ Friend)
|
calling all SQL programmers: need a query which will return all rows in table a that are not also in table b. I assume a join is needed, but I suck at joins If you'd like to help then um... i can give you $!
I suppose if I looked hard enough I could figure it out myself, but that'd be time consuming
Thanks in advance.
BTW, if multible queries are needed, post them all. Thx.
|
28.01.04 01:21 Post #1 | [Hide Sig (3)] [Profile] [Quote] |
Glenn
Forsetti Send PM Posts: 4241
Threads: 98 Mood: Godly Money: £8.24 (D) (+ Friend)
|
I suppose this is to solve the table breaking problem? Alright, I've got a few people I can ask on another forum, I'll get back to you with any news.
|
28.01.04 01:26 Post #2 | [Youtube] [Hide Sig (12)] [Profile] [Quote] |
Bloopy
Lazy, Busy, Fizzy, Crazy Send PM
Posts: 2996
Threads: 145 WA Clan: WwA Money: £764.65 (D) (+ Friend)
|
I may not know much about mysql but I do know a bit of the sql itself. Using EXCEPT in the following way will take all rows from table_a and subtract any that have a match in table_b. Replace the *s with whatever
columns you are checking for (eg which names appear in table_a and not table_b), just ensure that both select statements return the same number of columns.
SELECT * FROM table_a
EXCEPT
SELECT * FROM table_b
You might need to do a bit more to then get the entire rows for the particular names or ids that appear in table_a and not table_b, so I imagine you might wanna do something like this (I don't trust myself 100% tho heh):
SELECT * FROM table_a WHERE table_a.ID IN
(
SELECT ID FROM table_a
EXCEPT
SELECT ID FROM table_b
)
maybe that gives you the idea even if it's not quite right, the important part is EXCEPT, which gives you the rows that appear in the first select but not in the second select (assuming mysql supports except... )
________________
I suppose that's one "good" thing about my degree (aero engineering), there aren't too many terms/words/etc that have "alternative" meanings.
What, like cockpits, turboshafts, thrust, nozzles, corkscrews, ram drag, payload, flaps, and wind tunnels? |
28.01.04 06:03 Post #3 | Last edited: 28.01.04 06:04 (Bloopy - 1 times) |
[Planet Bloopy] [Hide Sig (7)] [Profile] [Quote] |
Zogger!
Looking For Status Send PM Posts: 3954
Threads: 62 Money: £93.82 (D) (+ Friend)
|
I get a feeling EXCEPT isn't in mysql... I've searched for it, but mysql isn't actually that good. There's no UNION or a number of other functions that I forget... Seeing as I don't know how to use them
________________
You know I'm a dancing machine |
28.01.04 15:23 Post #4 | [Hide Sig (8)] [Profile] [Quote] |
Bloopy
Lazy, Busy, Fizzy, Crazy Send PM
Posts: 2996
Threads: 145 WA Clan: WwA Money: £764.65 (D) (+ Friend)
|
If there's no union then it won't have except either.
________________
I suppose that's one "good" thing about my degree (aero engineering), there aren't too many terms/words/etc that have "alternative" meanings.
What, like cockpits, turboshafts, thrust, nozzles, corkscrews, ram drag, payload, flaps, and wind tunnels? |
28.01.04 15:39 Post #5 | [Planet Bloopy] [Hide Sig (7)] [Profile] [Quote] |
CBWhiz
Looking For Status Send PM Posts: 1044
Threads: 130 Money: £1343.20 (D) (+ Friend)
| |
28.01.04 18:06 Post #6 | [Hide Sig (3)] [Profile] [Quote] |
CBWhiz
Looking For Status Send PM Posts: 1044
Threads: 130 Money: £1343.20 (D) (+ Friend)
|
BTW, bloopy, mySQL can't do subselects either. the best it can do is create a temporary table, then use that in new queries.
|
28.01.04 18:08 Post #7 | [Hide Sig (3)] [Profile] [Quote] |
CBWhiz
Looking For Status Send PM Posts: 1044
Threads: 130 Money: £1343.20 (D) (+ Friend)
| |
28.01.04 18:15 Post #8 | [Hide Sig (3)] [Profile] [Quote] |
CBWhiz
Looking For Status Send PM Posts: 1044
Threads: 130 Money: £1343.20 (D) (+ Friend)
|
ignore this:
Backup Statement is "INSERT INTO `users_backup` SELECT * FROM `users`"
|
28.01.04 18:21 Post #9 | [Hide Sig (3)] [Profile] [Quote] |
CBWhiz
Looking For Status Send PM Posts: 1044
Threads: 130 Money: £1343.20 (D) (+ Friend)
|
Digging in mySQL docs are useful.
Query found:
SELECT users_backup. *
FROM users_backup
LEFT JOIN users ON users.id = users_backup.id
WHERE users.id IS NULL
|
28.01.04 18:40 Post #10 | [Hide Sig (3)] [Profile] [Quote] |
Zogger!
Looking For Status Send PM Posts: 3954
Threads: 62 Money: £93.82 (D) (+ Friend)
|
UNION is implemented in MySQL 4.0.0.
okay, so it's there, just not in the versions that are most used...
and...
Starting with version 4.1, MySQL supports all subquery forms and operations which the SQL standard requires, as well as a few features which are MySQL-specific.
...
For MySQL versions prior to 4.1, most subqueries can be successfully rewritten using joins and and other methods.
Client API version 3.23.49
________________
You know I'm a dancing machine |
29.01.04 09:18 Post #11 | [Hide Sig (8)] [Profile] [Quote] |
CBWhiz
Looking For Status Send PM Posts: 1044
Threads: 130 Money: £1343.20 (D) (+ Friend)
|
Actually we're in version 4.0.something, do a SELECT VERSION()
I dindn't notice that until afterward.
BTW, Zog, can you enable CREATE TEMPORARY TABLE permission for the site's db account? Be pretty convienet.
Also, you cant do CREATE TABLE _ LIKE _ which was annoying, took me awhile to figure out i had to do a CREATE TABLE _ INSERT _ WHERE 1=2
|
29.01.04 18:14 Post #12 | [Hide Sig (3)] [Profile] [Quote] |
Zogger!
Looking For Status Send PM Posts: 3954
Threads: 62 Money: £93.82 (D) (+ Friend)
|
BTW, Zog, can you enable CREATE TEMPORARY TABLE permission for the site's db account? Be pretty convienet.
erm, no I don't think I can actually... unfortunately I haven't got that kind of control
________________
You know I'm a dancing machine |
31.01.04 20:34 Post #13 | [Hide Sig (8)] [Profile] [Quote] |
Your Comments: