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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:12:36+00:00 2026-06-12T13:12:36+00:00

EDIT: Here’s my table: CREATE TABLE IF NOT EXISTS `punch` ( `name` varchar(50) NOT

  • 0

EDIT:
Here’s my table:

CREATE TABLE IF NOT EXISTS `punch` (
  `name` varchar(50) NOT NULL,
  `date` varchar(50) NOT NULL,
  `duration` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `punch` (`name`, `date`, `duration`) VALUES
('foo', '1', 2),
('bar', '1', 3),
('bar', '2', 5),
('foo', '3', 6),
('foo', '4', 8),
('bar', '4', 9);

I have table with values below:

SELECT * FROM `punch` P1 WHERE P1.date BETWEEN 1 AND 3 ORDER BY P1.name , date;

result:

name    date    duration
bar        1    3
bar        2    5
foo        1    2
foo        3    6

I want to make a report for date 1 until 3 like this:

name    date    duration
bar        1    3
bar        2    5
bar        3    null
foo        1    2
foo        2    null
foo        3    6

I tried this query (note the commented WHERE):

SELECT * FROM (
    SELECT DISTINCT date FROM punch WHERE date BETWEEN 1 AND 3
) P1
LEFT JOIN (
    SELECT * FROM punch -- WHERE name = 'bar'
) P2 ON P1.date=P2.date

ORDER BY P2.name, P1.date

I got result:

date    name    date    duration
1       bar     1       3
2       bar     2       5
1       foo     1       2
3       foo     3       6

I was expecting something like:

date    name    date    duration
2       NULL    NULL    NULL
3       NULL    NULL    NULL
1       bar     1       3
2       bar     2       5
1       foo     1       2
3       foo     3       6

Now, when I remove the commented WHERE, I got result:

date    name    date    duration
3       NULL    NULL    NULL
1       bar     1       3
2       bar     2       5

My question is, why LEFT JOIN above, behaves like INNER JOIN when there’s no WHERE clause?

And what is the correct query for my expected report above?

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-12T13:12:37+00:00Added an answer on June 12, 2026 at 1:12 pm

    Hi something like this gonna work:)

     SELECT DISTINCT 
        P1.name, 
        P2.date,
        (SELECT PP.duration 
         FROM punch PP 
           WHERE P1.name = PP.name
             AND P2.date = PP.date ) AS duration
        FROM
          (SELECT DISTINCT name FROM  `punch`) P1,
          (SELECT DISTINCT date FROM punch)P2
            WHERE P2.date BETWEEN 1 AND 3
            ORDER BY P1.name , P2.date
    

    Results:

    NAME    DATE    DURATION
    bar        1    3
    bar        2    5
    bar        3    (null)
    foo        1    2
    foo        2    (null)
    foo        3    6
    

    SQLFIDDLE example

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

Sidebar

Related Questions

EDIT: Here's a create script for the table minus the constraints on the keys
When inserting values into my table what do I edit here? Do I delete
[EDIT: Here's a link to a mockup of what I'm trying to create] http://i53.tinypic.com/w9v2np.jpg
What tools are used to create installers like this: EDIT: Here's a full tutorial:
EDIT: Here is the entire chunck of what is in the table Hopefully this
EDIT: Here is the edited control file (control.ascx): <%@ Control Language=C# AutoEventWireup=true CodeFile=Sale.ascx.cs Inherits=Enmasse.Modules.Demo_Enmasse.Sale
When a user links to link it redirects to edit.php - here's an example:
I'm looking to analyze and compare the following `signals': (Edit: better renderings here: oscillations
EDIT - The code looks strange here, so I suggest viewing the files directly
EDIT: See this in action here: http://jsbin.com/emobi/5 -- and that's using mouseenter/mouseleave. I have

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.