Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
HELP with mysql query
Old 12-20-2006, 04:23 PM HELP with mysql query
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
HI,

ive just been shown a sql query which works fine but i can seem to get my head arorund it.
Basically, i look at it, and it's quite obvious it's creating relationships between tables but it's so confusings.
My question is , why has my friend coded this was and not used joins?
Also.. if this is a way of coding sql, what reference would it be under?

cheers

Code:
SELECT groups.groupID,
			group_types.groupName,
	        group_types.groupImageURL,
	        group_types.groupImageHeight,
	        group_types.groupImageWidth,
            revisions.itemHeading,
	        revisions.itemContent,
	        revisions.itemExtra,
	        revisions.itemImageURL,
	        revisions.itemImageHeight,
	        revisions.itemImageWidth,
	        revisions.itemImageAlt,
	        item_types.typeClass
	FROM    news_item_groups groups,
	        news_item_group_types group_types,
	        news_category_columns cols,
	        news_categories cats,
	        news_items items,
	        news_item_revisions revisions,
		    news_item_types item_types
	WHERE   groups.issueID = '$issueID'
	AND     groups.typeID = group_types.typeID
	AND     group_types.columnID = cols.columnID
	AND     item_types.columnID = cols.columnID
	AND     cols.categoryID = cats.categoryID
	AND     cats.categoryName = 'Sunday Papers'
	AND     cols.columnName = 'News'
	AND     cats.isLIVE
	AND     cols.isLIVE
	AND     items.groupID = groups.groupID
	AND     items.isLIVE
	AND     items.itemID = revisions.itemID
	AND     revisions.isCurrent = 1
	AND     revisions.typeID = item_types.typeID
	ORDER BY groups.displayOrder,
    	     groups.groupID,
	         items.displayOrder,
	         items.itemID
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 12-20-2006, 05:15 PM Re: HELP with mysql query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It is an implied JOIN.

In effect it is an INNER JOIN designed to pull a recordset from 3 tables using criteria from various columns in tables.
You should be careful when using an implied JOIN as different databases may treat the query differently depending on the optimisation engine and you could end up with some unexpected results.
So if you are building a cross SQL database platform you should use an explicit JOIN syntax
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-20-2006, 05:23 PM Re: HELP with mysql query
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
great thanks for your quick response.

personally. i would never have done like this and would have used explicit JOIN. i dont actually know any differnt. this is in fact given by someone new in the office. He comes from a oracle background.

When you mention,

different databases may treat the query differently depending on the optimisation engine and you could end up with some unexpected results.

could you elaborate a little by what mean? We have a mysql database, with multiple tables but unsure about when you statement would effect me
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 12-20-2006, 07:32 PM Re: HELP with mysql query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The database "engine" is how the DBMS "talks" to the database and each engine has different ways of storing and indexing the data.

Jet, InnoDB & MyISAM are engine types. The SQL command text has to be converted into the native commands for the engine. So depending on how the engine algorithm is written for data access the order of the implied JOIN may not be the same in each engine.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-21-2006, 03:50 AM Re: HELP with mysql query
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
Thanks chrishirst,
Any idea what what the unexpected results might be?
Also, Why I should necessarilly use explicit join with MYSQL? By this I mean , isnt there the possibliity that implied joins are more than usable in mySQL if optimisation engine create algorithm suited to implied joins.

Im trying to figure if i should rewrite this query for the sake of getting it right
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 12-21-2006, 04:25 AM Re: HELP with mysql query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
What may happen with some versions is that you would get more (or less) records returned than expected.
If it gets treated as a CROSS JOIN you could get a recordset with many duplicated entries where the criteria matched.

If it works as expected in MySQL, then it shouldn't be a problem as far as recordsets go, although there may be a performance degredation between the implied and explicit syntax. This may or may not be a major concern depending on how your app is going to scale up in the future.

Personally I prefer to use the explicit syntax. That way I know how the recordset will be returned. There is no ambiguity in what may be interpreted on cross SQL platforms and when I come back to the app months later I will know what was required from the query.
It also improves the "readability" of the code, so if someone else has to alter the code they can see what it does.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-21-2006, 06:41 AM Re: HELP with mysql query
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
thanks chrishirst
youve helped me loads here and much appreciated.
Merry xmas
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 12-23-2006, 03:15 AM Re: HELP with mysql query
technoguy's Avatar
Extreme Talker

Posts: 151
Trades: 2
Jet, InnoDB & MyISAM are engine types. The SQL command text has to be converted into the native commands for the engine. So depending on how the engine algorithm is written for data access the order of the implied JOIN may not be the same in each engine.
technoguy is offline
Reply With Quote
View Public Profile
 
Old 12-23-2006, 05:56 AM Re: HELP with mysql query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
There must be an echo in here.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-23-2006, 05:57 AM Re: HELP with mysql query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
here


here

here
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to HELP with mysql query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.96213 seconds with 12 queries