The Church Media Community
Equipping You to Communicate Effectively
support CMN & share a
library of 19K+ images, videos, etc
Go Pro!
 
Go Back   The Church Media Community > Website Design > Website Coding Discussions
Forgot Password?
                          Register

Website Coding Discussions PHP, MySQL, Java, Javascript, ASP, etc.

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old Thursday, June 19th, 2008, 06:16 AM
danroth's Avatar
CMN MediaWallah
Become a CMN Professional Member!

 
 Join Date: Sep 2003 
 Last Online: Saturday, May 5th, 2012 
MySQL Help, Please

okay, I'm still not good with multi-table MySQL commands
(which, of course, is how all the really cool stuff gets done)

Can someone please help with a query to do the following:

Select table1.name where [table1.name is not in table2.name] and [table1.name is not in table3.name]

TIA!
Reply With Quote Start a New Topic From This Comment
  #2 (permalink)  
Old Thursday, June 19th, 2008, 06:42 AM
hussra's Avatar
Richard Huss

 
 Join Date: May 2006 
 Last Online: Tuesday, May 8th, 2012 
 Blog Entries: 3
I get to work with MS SQL Server rather than MySQL, but you want something along the lines of:

Code:
select table1.name from table1
where table1.name not in (select table2.name from table2)
and table1.name not in (select table3.name from table3)
See http://dev.mysql.com/doc/refman/5.0/...ubqueries.html and http://dev.mysql.com/doc/refman/5.0/...ubqueries.html.
Reply With Quote Start a New Topic From This Comment
The Following User Says Thank You to hussra For This Useful Post:
danroth (Thursday, June 19th, 2008)
  #3 (permalink)  
Old Thursday, June 19th, 2008, 07:07 AM
danroth's Avatar
CMN MediaWallah
Become a CMN Professional Member!

 
 Join Date: Sep 2003 
 Last Online: Saturday, May 5th, 2012 
Yes, I want something along those lines.

[geezer]I was hoping for one of those "INNER JOIN"s or something else like the kids use nowadays.[/geezer]
Reply With Quote Start a New Topic From This Comment
  #4 (permalink)  
Old Thursday, June 19th, 2008, 07:35 AM
hussra's Avatar
Richard Huss

 
 Join Date: May 2006 
 Last Online: Tuesday, May 8th, 2012 
 Blog Entries: 3
Quote:
Originally Posted by danroth View Post
[geezer]I was hoping for one of those "INNER JOIN"s or something else like the kids use nowadays.[/geezer]
I'm not really thinking straight this afternoon but I think you want to do a left outer join with table2 and then "where table2.name is null"? Then ditto with table3.

Something vaguely like this?

Code:
select table1.name from table1
left outer join table2 on table1.name = table2.name
left outer join table3 on table1.name = table3.name
where table2.name is null
and table3.name is null
I need a cup of tea now!
Reply With Quote Start a New Topic From This Comment
The Following User Says Thank You to hussra For This Useful Post:
danroth (Thursday, June 19th, 2008)
  #5 (permalink)  
Old Thursday, June 19th, 2008, 09:02 AM
waynehoskins's Avatar
The Crazy Analog Guy
Become a CMN Professional Member!

 
 Join Date: May 2006 
 Last Online: Today 
Yep, the left join on the null condition is the way to do it.

"outer" is optional; by default a left join is a left outer join.

You're looking to, for example, return the list of people who own property in Dallas County (table1) but do not own property in either Collin or Tarrant counties, something like that?
Reply With Quote Start a New Topic From This Comment
The Following User Says Thank You to waynehoskins For This Useful Post:
danroth (Thursday, June 19th, 2008)
  #6 (permalink)  
Old Thursday, June 19th, 2008, 09:03 AM
danroth's Avatar
CMN MediaWallah
Become a CMN Professional Member!

 
 Join Date: Sep 2003 
 Last Online: Saturday, May 5th, 2012 
Quote:
Originally Posted by waynehoskins View Post
You're looking to, for example, return the list of people who own property in Dallas County (table1) but do not own property in either Collin or Tarrant counties, something like that?
that's correct
Reply With Quote Start a New Topic From This Comment
  #7 (permalink)  
Old Thursday, June 19th, 2008, 09:10 AM
danroth's Avatar
CMN MediaWallah
Become a CMN Professional Member!

 
 Join Date: Sep 2003 
 Last Online: Saturday, May 5th, 2012 
okay, to throw a wrench in it (feel free to tell me to RTM) -
what if one of those tables is in a different database?
Reply With Quote Start a New Topic From This Comment
  #8 (permalink)  
Old Thursday, June 19th, 2008, 09:43 AM
hussra's Avatar
Richard Huss

 
 Join Date: May 2006 
 Last Online: Tuesday, May 8th, 2012 
 Blog Entries: 3
Quote:
Originally Posted by danroth View Post
okay, to throw a wrench in it (feel free to tell me to RTM) -
what if one of those tables is in a different database?
Assuming the different database is at least on the same server... you can then just use db_name.table_name and db_name.table_name.column_name in place of table_name and table_name.column_name.
Reply With Quote Start a New Topic From This Comment
The Following User Says Thank You to hussra For This Useful Post:
danroth (Thursday, June 19th, 2008)
  #9 (permalink)  
Old Thursday, June 19th, 2008, 09:47 AM
danroth's Avatar
CMN MediaWallah
Become a CMN Professional Member!

 
 Join Date: Sep 2003 
 Last Online: Saturday, May 5th, 2012 
yeah, they are same server


Thanks everybody, you've been a big help!!!
Reply With Quote Start a New Topic From This Comment
  #10 (permalink)  
Old Thursday, June 19th, 2008, 10:31 AM
waynehoskins's Avatar
The Crazy Analog Guy
Become a CMN Professional Member!

 
 Join Date: May 2006 
 Last Online: Today 
See, occasionally we are useful!

Glad to help.
Reply With Quote Start a New Topic From This Comment
Reply

  The Church Media Community > Website Design > Website Coding Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:



Add to Google


Register Now for FREE!
Our records show you have not yet registered to our community. To sign up for your FREE account INSTANTLY fill out the form below!

Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Agree to forum rules 


All times are GMT -6. The time now is 01:02 PM.

   
 
© 1995-2008, ChurchMedia™, ChurchMedia LLC

SEO by vBSEO 3.1.0