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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:15:18+00:00 2026-06-05T19:15:18+00:00

SELECT * From `users` AS `User` LEFT JOIN `selections` AS `Selections` ON (`Selections`.`user_id` =

  • 0
SELECT * From `users` AS `User`
LEFT JOIN `selections` AS `Selections` ON (`Selections`.`user_id` = `User`.`id`)
LEFT JOIN  `clients` AS `Client` ON (`Client`.`id` = `Selections`.`client_id`)
LEFT JOIN  `client_stats` AS `ClientsStat` ON (`ClientsStat`.`date` = """DATE1""")

The thing is I would like to have the values of some fields in ClientsStat where date = “DATE1” minus the same fields but with a date #2 But I am not sure how can I do that while in a LEFT JOIN. I tried while doing an other LEFT JOIN to the same table and renaming it and subtracting but the execution time were extremely high so i guess my method was bad.

EDITING:

My result is something like:

USER => fields...
SELECTIONS => fields...
CLIENTS => fields..
CLIENT_STATS => field x,y,z on date = date 1

and so on.

I would like this:

USER => fields
USERSELECTIONS => fields...
CLIENTS => fields..
CLIENT_STATS => field x,y,z when client_stats.date = date1 MINUS field x,y,z when client_stats.date = date2

etc.

  • 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-05T19:15:21+00:00Added an answer on June 5, 2026 at 7:15 pm

    You should be good with a double join on the stats. Performance, I would guess is based on indexes. However, are you sure you mean left-join (only required on the first table regardless of match on the second). Or… do you mean an INNER JOIN — you are EXPECTING RECORDS ON BOTH SIDES of the join. If you are trying to subtract the values from one record date vs another, I would expect BOTH entries to be found. I’ve written as basis of a “JOIN” (both sides must exist) instead of “LEFT JOIN”.

    SELECT 
          U.* 
          CS1.x - CS2.x as XDiff,
          CS1.y - CS2.y as YDiff,
          CS1.z - CS2.z as ZDiff
       From 
          users U
             JOIN selections S
                ON U.ID = S.User_ID
                JOIN clients C
                   ON S.Client_ID = C.ID
                   JOIN  client_stats CS1
                      ON ( C.ID = CS1.Client_ID AND CS1.`date` = YourFirstDateVariable )
                   JOIN  client_stats CS2
                      ON ( C.ID = CS2.Client_ID AND CS2.`date` = YourSecondDateVariable )
    

    Not absolutely sure if this is what you were looking for, but I would think one element you missed was a join to the client stats table on just the date… you had no qualifier on WHICH client ID and thus was probably the failure for your performance. Ensure client_Stats has an index on (client_id,date) — provided this IS the case that client_id was missing and IS part of the client_stats table.

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

Sidebar

Related Questions

I Want To Join 2 Selections one: SELECT user_email FROM users WHERE user_id =
Say I have the following: $query = SELECT user_id,email,password, roles.role_id,role_name FROM users JOIN roles
I have a select query which works: SELECT actions.id FROM actions LEFT JOIN users
i have this query that works fine SELECT t.username FROM users t LEFT JOIN
I have a query similar to the following: SELECT users.id FROM users LEFT JOIN
This problem is baffling me: BEGIN; INSERT INTO sub_users(user_id, email) SELECT user_id FROM users
select * from users, awards where (users.id = awards.user_id) and awards.trophy_id not in (select
I have this working query: $q = $this->db->query('SELECT u.name FROM users u JOIN user_group
I have a query like this SELECT user_id FROM user WHERE user_id NOT IN
Here's my SQL statement: SELECT * FROM `message_users` LEFT JOIN `messages` ON message_users.message_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.