BlameThePixel!

BTForum » BlameTheOffTopic Forums » BlameTheGeneralOffTopic » Calling all SQL programmers

[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
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)
Not online within the last half an hour
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]
[S]Bloopy
Lazy, Busy, Fizzy, Crazy
Send PM
An Avatar
Posts: 2996
Threads: 145
WA Clan: WwA
Money: £764.65 (D)
(+ Friend)
Not online within the last half an hour
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... :))

________________

Quoted :: Bloopy

Quoted :: thomasp
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]
[S]Zogger!
Looking For Status
Send PM
Posts: 3954
Threads: 62
Money: £93.82 (D)
(+ Friend)
Not online within the last half an hour
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]
[S]Bloopy
Lazy, Busy, Fizzy, Crazy
Send PM
An Avatar
Posts: 2996
Threads: 145
WA Clan: WwA
Money: £764.65 (D)
(+ Friend)
Not online within the last half an hour
If there's no union then it won't have except either. :|

________________

Quoted :: Bloopy

Quoted :: thomasp
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]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
28.01.04 18:06
Post #6
[Hide Sig (3)] [Profile] [Quote]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
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]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
Nevermind what I just said :D http://www.mysql.com/doc/en/Subqueries.html
28.01.04 18:15
Post #8
[Hide Sig (3)] [Profile] [Quote]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
ignore this:
Backup Statement is "INSERT INTO `users_backup` SELECT * FROM `users`"
28.01.04 18:21
Post #9
[Hide Sig (3)] [Profile] [Quote]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
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]
[S]Zogger!
Looking For Status
Send PM
Posts: 3954
Threads: 62
Money: £93.82 (D)
(+ Friend)
Not online within the last half an hour

Quoted :: mysql man

UNION is implemented in MySQL 4.0.0.


okay, so it's there, just not in the versions that are most used...

and...


Quoted :: MySql Man

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.



Quoted :: phpinfo

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]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
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]
[S]Zogger!
Looking For Status
Send PM
Posts: 3954
Threads: 62
Money: £93.82 (D)
(+ Friend)
Not online within the last half an hour

Quote:

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]

Post Reply

Jump To:


Your Comments:

Donate to BlameThePixel:
Donate to BTP Via PayPal


[22 Queries, Page Loaded in 0.399679 Seconds]

ShoutMeUp

Xmas Greetings from waka waka waka waka []Unvalidated EmailChristmasRiddle MERRY CHRISTMAS EVERYONE! []Spleet Except for Spleet. []TheAbdBoy Always bummin' a brother out. []Spleet Happy New Year everyone! But Spleet. []TheAbdBoy

Word Association

All

-10 Ago-

MiddleEastern []AlphaWolf camel [S]Bloopy toe []TheAbdBoy moose knuckle [S]Bloopy MeatLoaf []Spleet IdDoAnything4Lo ve []AlphaWolf rub n tug []TheAbdBoy tugboat []The Pope rope [S]Bloopy race []TheAbdBoy

-Latest-


Must be logged in to add new words

FictoLeague

You have to be logged in to vote...

Member Stats

Date: 24.11.24.
Members: 4731.
Latest: []Unvalidated Emailsdsakldsaldklasdsdsa
Active:
0 user(s)
1 guest(s)

On chat:
Lots of people

Files: 3330

Bloopy's Site
Get Firefox Get Opera Donate to BTP Via PayPal