Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:57:04+00:00 2026-06-06T00:57:04+00:00

I need help with optimizing some of my SQL queries. I’m not good in

  • 0

I need help with optimizing some of my SQL queries. I’m not good in SQL performance. I have a SQL Server 2008 RS Express and I can’t use DTA.

May be can help me with optimising and manually creating indexes for these two queries:

SELECT tblBlogs.RecordID, tblBlogs.RecordText, tblBlogs.CDate, tblBlogs.UserID, tblBlogs.Comments, tblUsers.Username, tblUserpics.UserpicName 
FROM  ( 
      SELECT tblBlogs_2.RecordID, tblBlogs_2.RecordText, tblBlogs_2.CDate, tblBlogs_2.UserID, COUNT(dbo.tblBlogComments.CommentID) AS Comments 
      FROM ( 
      SELECT TOP (150) RecordID, RecordText, CDate, UserID 
           FROM dbo.tblBlogs AS tblBlogs_1 
           ORDER BY RecordID DESC 
           ) AS tblBlogs_2 
      LEFT OUTER JOIN dbo.tblBlogComments ON tblBlogs_2.RecordID = tblBlogComments.RecordID
      GROUP BY tblBlogs_2.RecordID, tblBlogs_2.RecordText, tblBlogs_2.CDate, tblBlogs_2.UserID 
     ) AS tblBlogs  
INNER JOIN dbo.tblUsers ON tblBlogs.UserID = tblUsers.UserID  
LEFT OUTER JOIN dbo.tblUserpics ON tblBlogs.UserID = tblUserpics.UserID
ORDER BY tblBlogs.CDate DESC

This must select top 150 ros from Blogs table with User details + Comments for every single Blog entry.

SELECT f.ForumID, f.ForumName, t.ThreadName, m.MsgID, m.MsgName, m.MsgBody, m.UserID,   m.CDate, m.IP, u.Username, tblCities.CityName, 
t.IsClosed, ISNULL(u.Msgs, 0) AS Posts, ISNULL(tblUserpics.UserpicName, '') AS UserpicName, t.IsPoll,  
t.IsPollMultiple, ISNULL(u.Crashes, 0) AS Crashes, 0 AS LastMsgID, m.IsFlood, ISNULL(u.RepaGood, 0) AS RepaGood, ISNULL(u.RepaBad, 0)  
AS RepaBad, ISNULL(dbo.vMsgsRepaGood.RepaGood, 0) AS MsgRepaGood, ISNULL(dbo.vMsgsRepaBad.RepaBad, 0) AS MsgRepaBad, t.ThreadID, 
tblUserPrivateStatuses.StatusName AS PrivateStatus 
FROM tblMsgs AS m  
INNER JOIN tblThreads AS t ON m.ThreadID = t.ThreadID 
INNER JOIN tblForums AS f ON t.ForumID = f.ForumID  
INNER JOIN tblUsers AS u ON m.UserID = u.UserID  
LEFT OUTER JOIN tblUserPrivateStatuses ON u.UserID = dbo.tblUserPrivateStatuses.UserID  
LEFT OUTER JOIN tblCities ON u.CityID = dbo.tblCities.CityID  
LEFT OUTER JOIN tblUserpics ON u.UserID = dbo.tblUserpics.UserID  
LEFT OUTER JOIN vMsgsRepaGood ON m.MsgID = vMsgsRepaGood.MsgID  
LEFT OUTER JOIN vMsgsRepaBad ON m.MsgID = vMsgsRepaBad.MsgID  
WHERE m.ThreadID = "& ThreadID & " AND IsFlood = 0 
GROUP BY f.ForumID, f.ForumName, t.ThreadName, m.MsgID, m.MsgName, m.MsgBody, m.UserID, m.CDate, m.IP, u.Username, tblCities.CityName, t.IsClosed, u.Msgs, dbo.tblUserpics.UserpicName, t.IsPoll, t.IsPollMultiple, u.Crashes, m.IsFlood, u.RepaGood, u.RepaBad, vMsgsRepaGood.RepaGood, vMsgsRepaBad.RepaBad, t.ThreadID, tblUserPrivateStatuses.StatusName 
ORDER BY m.CDate</pre>

This query selects all not flood messages from specific Thread from specific Forum with User details (Registration date, number of good/bad reputation, number of crashes, number of post on this whole forum, city, userpic).

Or maybe somebody can tell me about free tools for optimizing queries and creating indexes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:57:06+00:00Added an answer on June 6, 2026 at 12:57 am

    There is a lot to talk about here, and without significantly more information, it’s going to be impossible for anyone to help with your query fully.

    Precaution: If you have a DBA for your system, check with them before indexing anything, especially on a live system. They can even help, if you’re nice to them. If the system is used by many others, be careful before changing anything like indexes.

    A basic tip on indexing, if you don’t want to dive deep into the problem, is: index by the following, in this order:

    1. Join predicates
    2. Filter
    3. Order by / Group By / etc.

    Also:

    • Make sure whatever columns possible are non-null.
    • Use data types that make sense – store nothing as varchar if it’s an integer or date. (Column width matters. Use the smallest data type you can, if possible.)
    • Make sure your joins are the same data type – int to int, varchar to varchar, and so on.
    • If possible, use unique, non-null indexes on each join predicate in each tables.

    Do all of this, and you’ll be well on your way. But if you need this stuff regularly, learn it! There is a lot out there, and it is a deep topic, but you can make queries MUCH better if you know what you are doing.

    Edit: The syntax for building indexes is here: How do I index a database column. The How/Why is here: How does database indexing work?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help optimizing the following method. The queries have become too costly
I need some help optimizing queries on 2 tables. One will contain about a
I need some help optimizing some queries for my database. I do understand the
need help/guide for sql select query, I have 2 table stock and stock_history, in
Need help with the codeigniter, I think file_exists is for server path, not for
I need some help optimizing a section of math heavy code. I've done the
I need some help optimizing a MySQL query or table When I run this
Need help with this SQL Server 2000 procedure. The problem is made difficult because
I need help optimizing the code to run faster, unless it is optimized the
Need help with a query that I wrote: I have three tables Company id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.