Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4200
Latest: [chrisB]
New This Month: 0
New This Week: 1
New Today: 0
Stats
Total Posts: 42613
Total Topics: 7433
Most Online Today: 98
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 40
Total: 40

Author Topic: SQL Help  (Read 101 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 663
    • View Profile
    • Homework Clinic - Your Academic Lifeline
SQL Help
« on: October 17, 2022, 09:34:28 pm »
Hello, I am seeking to get a count of topics given the following code. However, it produces over 500,000 topics, which is exhausting the server. I want to limit it to the first 1000 results, but the LIMIT feature isn't working. Apparently there is a solution here, but I can't get it to work.

Do you have any suggestions?

Code: [Select]
$request = db_query("
 SELECT COUNT(DISTINCT t.ID_TOPIC)
 FROM ({$db_prefix}topics AS t, {$db_prefix}boards AS b)
 
INNER JOIN {$db_prefix}messages AS m ON (m.ID_MSG = t.ID_FIRST_MSG)
 
 WHERE b.ID_BOARD = t.ID_BOARD
 AND $query_this_board
 AND m.topicSolved = 0 AND t.ID_FIRST_MSG = t.ID_LAST_MSG", __FILE__, __LINE__);

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16161
    • View Profile
Re: SQL Help
« Reply #1 on: October 17, 2022, 11:12:06 pm »
The first topics in the board or the latest topics? LIMIT should work at the end of the query.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

 

+- Recent Topics

List of changes in SMFGallery by Monocero
Today at 06:23:53 am

Permissions query by davejo
November 30, 2022, 09:52:38 am

Errors with SMF2WPBridge by [chrisB]
November 29, 2022, 04:30:26 pm

"Notify all store admins of item purchase" Not Working in SMF 2.1.2 or 2.1.3 by SMFHacks
November 29, 2022, 01:15:50 pm

Undefined index: id by Shades
November 29, 2022, 12:15:20 pm

Additional Recommendations for SMF Store by Michael Vail
November 26, 2022, 12:49:58 pm

SMF Store 5.0 Beta Errors - Trying to access array offset on value of type null by Michael Vail
November 26, 2022, 12:07:42 pm

Modification: Subcategories total in main gallery view by VisiGod
November 26, 2022, 11:27:34 am

Change log for Downloads Pro 6.13 and 6.14 by Nicole
November 20, 2022, 08:24:34 am

Release date? by SMFHacks
November 20, 2022, 08:09:10 am

Powered by EzPortal