den: (Default)
den ([personal profile] den) wrote2002-03-31 02:24 pm

(no subject)

bloody SQL assignment is killing me.

"List all data from the Person table who are niether staff nor patients."

fucked if I know.

Why does

WHERE person.person_id = staff.person_id
AND person.person_id = admission.patient_id


work and

WHERE person.person_id <> staff.person_id
AND person.person_id <> admission.patient_id


not?

[identity profile] moonrose.livejournal.com 2002-03-30 08:28 pm (UTC)(link)
select * from Person where type [or whatever the column is] not in ('staff', 'patient')?

[identity profile] moonrose.livejournal.com 2002-03-30 08:29 pm (UTC)(link)
if it isn't MSSQL though, you prolly need a semicolon at the end, and the syntax might be a bit different. bloody MS ;)

[identity profile] mmmetta.livejournal.com 2002-03-30 08:35 pm (UTC)(link)
dunno about access, but my guess would be because it's comparing strings. if you compared numbers you'd be able to get away with <>, i think. if its valid syntax anyway.

[identity profile] moonrose.livejournal.com 2002-03-30 08:37 pm (UTC)(link)
the strings thing is my guess too. i've been lucky and managed to avoid Access for the most part. :/

[identity profile] mmmetta.livejournal.com 2002-03-30 08:33 pm (UTC)(link)
mysql likes semi colons at the end, i have no idea what microsoft wants with its sql... it's bound to be different in some special unique and entirely wrong way :-)

[identity profile] mmmetta.livejournal.com 2002-03-30 08:29 pm (UTC)(link)
select * from persons where type not in ("staff","patients");

that's more or less what it should be, but 'type' would be the field you're using for the staff/patient flag. lemme know if that works, it's just off the top of my head.

[identity profile] moonrose.livejournal.com 2002-03-30 08:31 pm (UTC)(link)
great minds think alike ;)

[identity profile] mmmetta.livejournal.com 2002-03-30 08:35 pm (UTC)(link)
heh, that one was a no-brainer. i'm just gonna have to hide later on when den gets to the more complex stuff. i didn't go much past first semester database stuff, and since then it's been real simple stuff for me ;-)

[identity profile] dewhitton.livejournal.com 2002-03-30 08:45 pm (UTC)(link)
Access is asking for a type parameter entry.

[identity profile] dewhitton.livejournal.com 2002-03-30 08:47 pm (UTC)(link)
we haven't covered TYPE in the course, so I suppose technically I shouldn't use it.

jeez I hate programming of any sorts

[identity profile] mmmetta.livejournal.com 2002-03-30 08:52 pm (UTC)(link)
it's always a toss-up as to whether or not to use stuff they haven't taught you... i usually go for the 'right' answer (the one i feel is the best way to do it) rather than putting up with what they teach you.

i guess that's why i never really stick with my comp sci courses, they just frustrate me too much.


[identity profile] writingstatic.livejournal.com 2002-03-30 09:10 pm (UTC)(link)
that's a theoretical question, right? how the hell should *i* know?

[identity profile] dewhitton.livejournal.com 2002-03-30 09:52 pm (UTC)(link)
Thanks moonrose and mmmetta. I owe youse tim tams.

[identity profile] charles.livejournal.com 2002-03-30 09:53 pm (UTC)(link)

To answer the question.

Imagine the world's most fucking insane DBA came up with the following tables:



Now, try the first select: "Select first_name, last_name from table_1, table_2 where table_1.id = table_2.id"


Starting at the first row. We have table_1.id = 1, and first_name = 'Charles'. Looking across to the second table, we find all the rows where table_1.id = table_2.id. There's only one of those rows, and that joins me across to my last name, 'Miller'. So the results table will be:





Now for the second query. "Select first_name, last_name from table_1, table_2 where table_1.id <> table_2.id"


First, we look at the first row. The first_name is 'Charles', and the id is 1. Now we look at the second table, and find our join is telling us "find all the rows where table_1.id is NOT the same as table_2.id." The first row doesn't match this condition, but the other two do. So the result of this query would be:



[identity profile] dewhitton.livejournal.com 2002-03-30 09:56 pm (UTC)(link)
Kilkennys for you!

Try this

[identity profile] berin.livejournal.com 2002-03-30 11:31 pm (UTC)(link)
Try:
It's not elegant, but it should work.

Select *
From person
where person.person_id not in (select staff.person_id from staff)
and person.person_id not in (select admission.patient_id from admission)

In other words, I want everything in set 1 that does not have a matching ID in set 2 or set 3. [Subquery solution]

Re: Try this

[identity profile] dewhitton.livejournal.com 2002-03-31 02:02 am (UTC)(link)
that's very close to the solution I worked out with [livejournal.com profile] charles on irc

Re: Try this

[identity profile] berin.livejournal.com 2002-03-31 05:19 am (UTC)(link)
Not too bad for 2 AM and slightly inebriated. I've been trained too well, as I can not let a question like that slip by without an answer.

my brain hurts

[identity profile] weyrdbird.livejournal.com 2002-03-31 01:22 am (UTC)(link)
Hooray for New MATH!
New Hoo Hoo Math!
It won't do you a bit of good to try and review math!
It's so simple, so very simple, that only a child can do it!!
-Tom Lehrer/New Math (after a long explanation of a hundreds multiplication table doone is base 8 with additions and distractions).

I can't even begin to decipher either problem. Just reading the abbreviations made my temples throb.I'll stick to HTML for dumbos.:D