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

  • SEARCH
  • Home
  • 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 4345316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:01:11+00:00 2026-05-21T12:01:11+00:00

I have a table I need to perform a horrible query on (not my

  • 0

I have a table I need to perform a horrible query on (not my db design).

The table is simple:

`id` bigint(255) NOT NULL AUTO_INCREMENT,
`poster` varchar(30) NOT NULL,
`chattext` varchar(255) NOT NULL,
`timeposted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`type` int(3) NOT NULL DEFAULT '0',
`towho` varchar(30) DEFAULT NULL

My current query does what I want, but at a horrible cost to the server. I’m running near max CPU with only a handful of users. Sadly, every 5 seconds they do this pull.

Current query:

SELECT c.poster, c.chattext, c.type, c.towho, c.timeposted, u.utype, u.locz
    FROM chat c
    LEFT JOIN users u ON c.poster=u.name
    WHERE c.type!=4
UNION (
    SELECT c.poster, c.chattext, c.type, c.towho, c.timeposted, u.utype, u.locz
        FROM chat c
        LEFT JOIN users u ON c.poster=u.name
        WHERE c.type=4  AND c.towho='USERNAME')
UNION (
    SELECT c.poster, c.chattext, c.type, c.towho, c.timeposted, u.utype, u.locz
    FROM chat c
    LEFT JOIN users u ON c.poster=u.name
    WHERE c.type=4 AND c.poster='USERNAME')
ORDER BY timeposted DESC LIMIT 0, 25"

This gets performed every 5 seconds by all users online. As you can see, it quickly becomes a resource hog.

I’m used to MSSQL so I should be able to grasp the concepts for MySql, and syntax hasn’t been too different. This query was given to me without the user tables added, so I think my mindset is stuck in making this work over finding a better way.

I think I’m doing this the wrong/complicated way. So any assistance in improving performance is appreciated.

  • 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-05-21T12:01:12+00:00Added an answer on May 21, 2026 at 12:01 pm

    I think this simpler query is equivalent to yours. isn’t it?

    SELECT c.poster, c.chattext, c.type, c.towho, c.timeposted, u.utype, u.locz
        FROM chat c
        LEFT JOIN users u ON c.poster=u.name
        WHERE c.type!=4
              OR
              (c.type=4 AND c.towho='USERNAME')
              OR
              (c.type=4 AND c.poster='USERNAME')
    ORDER BY timeposted DESC LIMIT 0, 25
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query I need to perform on a table that is roughly
I have three table I need to query table 1,2 and 3 and select
I have a table with 117000 or so records. I need to perform a
I have a table Studies that I perform a SELECT on. I then need
I need to perform normalization on data structure. I have one table with lots
I need to perform the following on MySQL/InnoDB. Assume I have a table consists
I have a table in MYSQL on which I need to perform a select
I have table 'products' and I need to update 'price' field by 20% if
I have table to test score data that I need to pivot and I
I have a table and I need to count all unique users on it.

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.