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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:28:02+00:00 2026-06-15T17:28:02+00:00

I have two tables. One contains default data for 3 columns, (value is 1

  • 0

I have two tables.

One contains default data for 3 columns, (value is 1 or 0) In the same table is a ClientID

Another table contains edited data with a date, ClientID and a extra column named ‘Changed’

If Changed = 1 then the values in the 3 columns are changed and therefore need to be read from the second table.

This al works fine, but I want to make a report in php where a daterange can be selected and a query should group by ClientID and count all 1’s in the selected daterange of the 3 columns. (Each column seperate)

Here’s the trick: When Changed = 0 in the specific row then It should check the default value and if Changed = 1 it should check the second table. And then count it with the previous rows.

I hope you understand what I want to create

  • 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-15T17:28:03+00:00Added an answer on June 15, 2026 at 5:28 pm

    You can use IF function from SQL

    For example

    SELECT SUM(IF(Changed=1, t1.col1, t2.col2)) FROM t1, t2 WHERE t1.id=t2.id
    

    This is example how you can use columns for case in SUM

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

Sidebar

Related Questions

I have two db tables. One table contains Forecast data. The second table contains
I have two tables that have the same structure; one contains permanaent data, and
I have two tables. One table contains words. Other table contains points. table words:
What I have is two tables inside of a mysql database. One table contains
I have two tables: one contains employees information and another is transactions (sales) information
I have two tables made in access. One table (Owner) contains: ownerID , name
I have two tables one named Person , which contains columns ID and Name
I have two tables, one contains the page/heading number and the heading text, the
I have two tables, one for routes and one for airports. Routes contains just
I have two tables one with ID and NAME table 1 ID | NAME

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.