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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:11:59+00:00 2026-06-13T07:11:59+00:00

I have this table : id | type | date 1 | a |

  • 0

I have this table :

id   |  type |      date    
 1   |    a  |   01/1/2012   
 2   |    b  |   01/1/2012
 3   |    b  |   01/2/2012   
 4   |    b  |   01/3/2012   
 5   |    a  |   01/5/2012   
 6   |    b  |   01/5/2012   
 7   |    b  |   01/9/2012   
 8   |    a  |   01/10/2012   

The POV is per date. if 2 rows contains the same date , so both will visible in the same line ( left join).

Same date can be shared by 2 rows max.

so this situation can’t be :

 1   |    a  |   01/1/2012   
 2   |    b  |   01/1/2012
 3   |    a  |   01/1/2012

if in the same date there is group a and b show both of them in single line using left join

if in date there is only a group , show it as single line ( +null at the right side )

if in date there is only b group , show it as single line ( +null at the left side )

Desired result :

   Date         |typeA|typeB  |a'id|b'id
  01/1/2012     |  a  |  b    | 1  |  2
  01/2/2012     |     |  b    |    |  3
  01/3/2012     |     |  b    |    |  4
  01/5/2012     |   a |  b    | 5  |  6
  01/9/2012     |     |  b    |    |  7
  01/10/2012    |   a |       | 8  |  

I know this suppose to be simple , but the main anchor of join here is the date.
The problem I’ve encountered is when I read line 1 , i search in the table all rows with the same date…fine. – its ok.

But when I read the second line , I do it also , and it yields the first row – which already was counted…

any help ?

here is the sql fiddle :

https://data.stackexchange.com/stackoverflow/query/edit/82605

  • 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-13T07:12:00+00:00Added an answer on June 13, 2026 at 7:12 am

    I think you want a pivot

     select 
        [date],
        case when [a] IS null then null else 'a' end typea,
        case when [b] IS null then null else 'b' end typeb,
        a as aid,
        b as bid
     from yourtable src
     pivot  (max(id) for type in ([a],[b]))p 
    

    If you want to do it with joins..

    select ISNULL(a.date, b.date), a.type,b.type, a.id,b.id
    from
    (select * from yourtable where type='a') a
        full outer join
    (select * from yourtable where type='b') b  
        on a.date = b.date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my table, I have Collection_Date and Tag_Date fields, both of type date .
I have a date field in the database table of this format 2012-02-1.i need
I have a MySQL table which contains the following type of information: Date product
I have the field: APP_DATE (smalldatetime) I'm doing this query: INSERT INTO table (TYPE,
I have this Points table: =========================================== FIELD : TYPE =========================================== id int(11) user_id int(11)
I have this two tables: Table A ID TYPE SDATE EDATE RATING 1 M
I have this mysql table called comments which looks like this: commentID parentID type
i have a table like this: Table(MissioneID, Type) Type can be 1,2 or 3
I have a table like this: num | type -----+------ 123 | 3 123
I have a table like this in my database (SQL Server 2008) ID Type

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.