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 7910095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:43:45+00:00 2026-06-03T12:43:45+00:00

I have a query like this: Select E.ID, E.NAME, date_format( CONVERT_TZ( CONVERT_TZ( E.ST, ‘+00:00’,

  • 0

I have a query like this:

  Select E.ID, E.NAME, 
     date_format(  CONVERT_TZ( CONVERT_TZ( E.ST, '+00:00', '+5:00' ),
     '+00:00', if( ET.GT LIKE '%.5', REPLACE( ET.GT, '.5', ':30' ) , CONCAT( ET.GT, ':00')
  ) ), '%Y-%m-%e %r'), concat( date_format(  CONVERT_TZ( CONVERT_TZ( E.ET, '+00:00', 
  '+5:00' ) ,   '+00:00', if( ET.GT LIKE '%.5', REPLACE( ET.GT, '.5', ':30' ) , CONCAT( 
  ET.GT, ':00' ) ) ), '%Y-%m-%e %r') , ' ', if ( TC is NULL, '', concat(TC, 'T'))),
  EE.CL, EC.EC, CONCAT( '##PATH##', E.ID, '/') 

and these fields are pulled from 4 different tables. The conditions, formatting stuff, etc is to convert the Date from Eastern to specific timezone per settings from one of the tables.

Certainly not a nice looking query :-). Here are the reason(s), I am trying to do all these wacky thing in on query.

  1. These results are returned as array and then encoded as JSON and sent back to the caller.
  2. I don’t have to loop through the results in the PHP. I can just pass the results as is.
  3. I don’t have to worry about extra columns that I don’t need. I can just pull only columns needed.

This is just working great for me!

But, from the performance and other design perspective(s):

Questions: Is it good to leave as is or I need think about doing the processing on PHP?
I will have to do two things when I remove the complexity in the query (If, Convert_Tz,etc)

  1. Loop through the returned array and call a function to calculate the Timezone.
  2. Remove the unnecessary array elements.

Your thoughts?

EDIT:

Here are the joins:

 LEFT JOIN eeemps EER ON e.id = EER.eid
 LEFT JOIN eemp Ee ON eer.empid = ee.empid
 LEFT JOIN EclassS EC ON E.EVN = EC.E_ID 
 LEFT JOIN E_tz NE ET ON E.TZID = ET.ID

 where date between x and y, and e_id = 123

Thats all “where” cond is. Ignore the table and field names. I changed them.

  • 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-03T12:43:48+00:00Added an answer on June 3, 2026 at 12:43 pm

    PHP part of your server probably already has some nice work, so doing the most possible in MySQL is the right way of dealing with a problem. Moreover, MySQL way is 99 times from 100 faster than PHP. And do not worry about large queries. If possible do some generation of the code to (for example joins) and also keep in mind that formatting is very important to make difficult things way easier.

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

Sidebar

Related Questions

Hi I have written this query SELECT cl_brands.name AS Brand,DATE_FORMAT(cl_doctor_call.date_entered,'%b%y')AS MonthYear, SUM(FIND_IN_SET(CONCAT('^',cl_brands.id,'^'),cl_doctor_call_cstm.brand_discussed_c))AS No_Times_Brand_Discussed FROM
I have a query like this SELECT TOWN, NAME FROM CINEMA WHERE CITY_ID =
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I like to have a query like this: select data from table where (x
I have a query like this SELECT user_id FROM user WHERE user_id NOT IN
Say I have a query like this: select ((amount1 - amount2)/ amount1) as chg
So lets say i have a query like this SELECT a as d,b,c FROM
I have a MySQL query like this: SELECT DAYNAME(CreatedAt) AS TheDay, SUM(Amount) AS TheSum
Lets say that we have a query like this one: SELECT *, (CUSTOM_EXPRESSION) as

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.