Skip navigation links

MySQL Forums :: General :: I need to better understand how to use self joins


Advanced Search

Re: I need to better understand how to use self joins
Posted by: Shawn Taylor ()
Date: April 24, 2012 01:05PM

It's not my schema so I can't change it.

I have cut the query time in half by eliminating one of the dependent queries and moving the where to the first part of the query.

SELECT DISTINCT substring_index(hostname,'-',-1) AS site
FROM `hosts` 
WHERE hostname like 'TERM%' and 
substring_index(hostname,'-',-1)  NOT IN 
(
	SELECT DISTINCT substring_index(hostname,'-',-1) FROM `hosts`  WHERE hostname LIKE 'SERV%'
)

I guess I'll have to live with that.

Thanks for the feedback.

Shawn

Options: ReplyQuote


Subject Written By Posted
I need to better understand how to use self joins Shawn Taylor 04/16/2012 08:44AM
Re: I need to better understand how to use self joins laptop alias 04/16/2012 10:31AM
Re: I need to better understand how to use self joins Rick James 04/17/2012 09:31PM
Re: I need to better understand how to use self joins Shawn Taylor 04/24/2012 01:05PM
Re: I need to better understand how to use self joins Peter Brawley 04/24/2012 03:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.