Notices
Non Scooby Related Anything Non-Scooby related

MySQL / SQL expert?? Your scoobynet needs YOU!! :D

Thread Tools
 
Search this Thread
 
Old May 26, 2001 | 11:18 PM
  #1  
SDB's Avatar
SDB
Thread Starter
Scooby Regular
 
Joined: Feb 1999
Posts: 1,727
Likes: 0
Talking

This is driving me up the bleedin' WALL!!...

OK..

I'm upsizing some ASP BBS software I wrote ages ago from Access to MySQL...

all was going really well until the following SQL (which worked lovely with Access) ...

SELECT tblSection.SectionName, tblSection.Order, tblForum.ForumID, tblForum.Name, tblForum.Description, Max(tblPost.Date) AS LastPost, Count(tblPost.PostID) AS Posts, Count(tblThread.ThreadID) AS Threads FROM (tblSection LEFT JOIN (tblForum LEFT JOIN tblThread ON tblForum.ForumID = tblThread.ForumID) ON tblSection.SectionID = tblForum.SectionID) LEFT JOIN tblPost ON tblThread.ThreadID = tblPost.ThreadID GROUP BY tblSection.SectionName, tblSection.Order, tblForum.ForumID, tblForum.Name, tblForum.Description ORDER BY tblSection.Order

produced the following error with MySQL...

Microsoft OLE DB Provider for ODBC Drivers (0x80040E09)
[TCX][MyODBC]You have an error in your SQL syntax near '(tblForum LEFT JOIN tblThread ON tblForum.ForumID = tblThread.ForumID) ON tblSec' at line 1

Any help would be INCREDIBLY gratefully received as I've been on it for about 5 hours now and can't find a solution!!

All the best

Simon
Reply
Old May 26, 2001 | 11:48 PM
  #2  
Lee's Avatar
Lee
Scooby Regular
 
Joined: Mar 1999
Posts: 1,681
Likes: 0
From: Essex
Lightbulb

Sorry Si but I think a rethink is needed.

A max(date) on the postings table , count on the postings table - will run like a dog.

A max is an index range scan on the date field (assuming its indexed) whereas a count is a full table scan.

I presume this is for displaying the section headers - date of last post, total posts in section etc.

What you need to do is store the date of last post and count of posts against the section rather than calculating them on the fly.

Generally (not always) when you have to write complicated SQL it means the basic database design needs refining.

Appreciate the question was how to make it work in mySQL rather than Access, but hey, just my 2p worth as a certified DBA
Reply
Old May 26, 2001 | 11:55 PM
  #3  
SDB's Avatar
SDB
Thread Starter
Scooby Regular
 
Joined: Feb 1999
Posts: 1,727
Likes: 0
Post

To be honest Lee I think you're right.

It is what I was planning to do originally, but just wanted to trial it to see what the overhead would be...

But another opinion, etc.. I think you're right.

Just didn't like the untidyness of having a table to store the info, but it's not exactly mission critical information, and I can always include an admin function to re-calc anyway.

Thanks for the advice.. if you can think of a way to restructure that SQL to get rid of the parentheses I would be grateful though, just so I can test it.

Cheers

Simon
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
neil-h
ScoobyNet General
6
Sep 27, 2015 11:27 AM
The Joshua Tree
Computer & Technology Related
18
Sep 11, 2015 09:24 PM




All times are GMT +1. The time now is 04:57 AM.