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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:05:54+00:00 2026-06-11T06:05:54+00:00

I have 2 tables: Product , User . Product: Date(Datetime) Phone_Number(Number). User: Date (Datetime)

  • 0

I have 2 tables: Product, User.

Product:
    Date(Datetime)
    Phone_Number(Number).

User: 
    Date (Datetime)
    Phone_Number(Number)
    Type(Value of N or C).

When a new user is added to the User table, it is given a date, Phone Number and value of “N” (N for New).
When a user gets cancelled, it is given a date, the Phone Number and value of “C” (C for Cancelled).

Using MySQL, I need to find out the date difference between the Date the user was created and the date the user was cancelled and if they had a product (can match the user to the product by Phone Number) between the date of the creation and the date of the cancellation.

Any assistance would be greatly appreciated as my Query writing isn’t terrible but this I can’t work out.

Thanks.

  • 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-11T06:05:55+00:00Added an answer on June 11, 2026 at 6:05 am

    You need to start by self-joining the User table to find the created and cancelled dates. Then join to the Product table to see if anything is there.

    SELECT u.Phone_Number, u.Created, u.Cancelled, p.Date as 'ProductDate'
    FROM (
        SELECT u1.Phone_Number, u1.Date as 'Created', u2.Date as 'Cancelled'
        FROM User u1
          JOIN User u2 on u1.Phone_Number=u2.Phone_Number
        WHERE u1.Type = 'N'
          and u2.Type = 'C'
      ) u
      LEFT JOIN Product p on u.Phone_Number = p.Phone_Number
                         and p.Date between u.Created and u.Cancelled
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables product and history product table: id name type price location
I have a single product table with multiple fields which contain user evaluations of
Let's say I have 2 tables, Message and Product. Whenever a user post a
I have a table of user activity. I have the HWA, the date of
I have a product table with 100000 products and also I have a user
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
I have two product tables Product1 and Product2. There is a one 2 one
Let's say I have two tables: Category and Product , and Product links to
i have two tables products and reviews each product has several reviews linked by
I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table

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.