Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 15 posts ] 
Author Message
 Post subject: SQL Gurus
PostPosted: Mon Jan 19, 2009 3:46 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49237
I'm having a mental block, would appreciate assistance from any folks out there better with SQL than me.

Table one has a list of users and the applications they use. Table two has a list of these applications and whether or not they work on Vista.

For example

Code:
User        |      App
Frank       |  Word
Frank       |  Excel
Steve       |  Word
Steve       |  Outlook
Lisa        |  Excel
Lisa        |  Outlook


App           |     Working
Word          |       Yes
Excel         |       Yes
Outlook       |       No


What I want to know is which users have all their applications working on Vista. Which in this case should just give me Frank. I'm having a complete brainfart. Help please!

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 4:45 
User avatar
What-ho, chaps!

Joined: 30th Mar, 2008
Posts: 2139
Get all the user names that have all of their app counterparts in the two table listed as working?

Rephrase that: get all the user names that have none of their app counterparts in the two table listed as not working and you've got:

Code:
SELECT DISTINCT `one`.`user`
FROM `one`
WHERE `one`.`user` NOT
IN (

SELECT `one`.`user`
FROM `one`
LEFT JOIN `two` ON `one`.`app` = `two`.`app`
WHERE `two`.`working` = 'no'
GROUP BY `one`.`user`
)


"That'll be twenty dollars!!"

_________________
[www.mrdictionary.net]


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 9:18 
User avatar
UltraMod

Joined: 27th Mar, 2008
Posts: 55717
Location: California
Code:
DELETE FROM App
WHERE User = Steve

_________________
I am currently under construction.
Thank you for your patience.


Image


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 9:57 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
MrD wrote:
"That'll be twenty dollars!!"
Look at all those backquotes! Someone's been bitten in the past with a whacky table or column name, I'm guessing?


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 10:27 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69668
Location: Your Mum
If you like joins:
Code:
SELECT User.* FROM User
LEFT JOIN App on User.App = App.App AND App.Working = 'no'
WHERE
App.App IS NULL

(assuming, obv, that the two tables are called App and User).

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 10:27 
User avatar

Joined: 30th Mar, 2008
Posts: 14312
Location: Shropshire, UK
No harm in being thorough :P


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 10:34 
User avatar
Gogmagog

Joined: 30th Mar, 2008
Posts: 48810
Location: Cheshire
A child of 8 could have worked that out, y'know :)

_________________
Mr Chris wrote:
MaliA isn't just the best thing on the internet - he's the best thing ever.


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 10:36 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49237
MrD wrote:
Solution


Cheers for that, still having issues though. Won't a left join return every single username in table One, regardless if there are matching applications in table Two?

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 10:40 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69668
Location: Your Mum
Craster wrote:
MrD wrote:
Solution


Cheers for that, still having issues though. Won't a left join return every single username in table One, regardless if there are matching applications in table Two?

Yes, right up until you kick all the non-null results out in the WHERE clause.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 11:36 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49237
Yay - it works, although it takes 3 and a half minutes to run.

Thanks folks!

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 11:49 
User avatar

Joined: 30th Mar, 2008
Posts: 14312
Location: Shropshire, UK
Three and a half minutes? Perhaps stick some indexes on the name columns?


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 11:59 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69668
Location: Your Mum
Or repair the tables.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 12:04 
User avatar
Gogmagog

Joined: 30th Mar, 2008
Posts: 48810
Location: Cheshire
Grim... wrote:
Or repair the tables.


If you had a table with 4 legs, and removed one, what would happen?

_________________
Mr Chris wrote:
MaliA isn't just the best thing on the internet - he's the best thing ever.


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 12:26 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49237
They're just very large tables, and it's a SQL 2005 DB running on top of my Vista desktop - you'll forgive it for not being lightning fast.

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: SQL Gurus
PostPosted: Mon Jan 19, 2009 14:19 
User avatar
What-ho, chaps!

Joined: 30th Mar, 2008
Posts: 2139
THAT'S AN ASSUMPTION.

_________________
[www.mrdictionary.net]


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Columbo and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.