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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:38:10+00:00 2026-06-07T18:38:10+00:00

Sql: SELECT date,total_usage_T1 as TotalUsageValue,’T1′ as UsageType FROM TblSayacOkumalari UNION ALL SELECT date,total_usage_T2 as

  • 0

Sql:

SELECT date,total_usage_T1 as TotalUsageValue,'T1' as UsageType FROM TblSayacOkumalari
UNION ALL
SELECT date,total_usage_T2 as TotalUsageValue,'T2' as UsageType FROM TblSayacOkumalari

And I try to do to convert it to linq

IEnumerable<TblSayacOkumalari> sayac_okumalari = entity.TblSayacOkumalari
.Select(x => new 
    { x.date, x.total_usage_T1 })
.Union(entity.TblSayacOkumalari.Select(x => new 
    { x.date, x.total_usage_T2 }));

But I dont know how to convert 'T1' as UsageType to linq. Also my union using is incorrect too.

My table fields like this:

| date | total_usage_T1 | total_usage_T2 |

| 2010 |             30 |             40 |
| 2011 |             40 |             45 |
| 2012 |             35 |             50 |

I want like this

| date | TotalUsageValue | UsageType     |

| 2010 |             30 |             T1 |
| 2011 |             40 |             T1 |
| 2012 |             35 |             T1 |
| 2010 |             40 |             T2 |
| 2011 |             45 |             T2 |
| 2012 |             50 |             T2 |

I tried very hard, but could not. Please help.

  • 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-07T18:38:11+00:00Added an answer on June 7, 2026 at 6:38 pm

    EDIT

    Def. from MSDN
    Enumerable.Concat  - Concatenates two sequences.
    Enumerable.Union    - Produces the set union of two sequences by using the default equality comparer.
    

    My post : Concat() vs Union()

        IEnumerable<TblSayacOkumalari> sayac_okumalari = 
       entity.TblSayacOkumalari
         .Select(x => new
              {     
                    date= x.date, 
                    TotalUsageValue = x.total_usage_T1,
                    UsageType     = "T1" 
               })
         .Concat(entity.TblSayacOkumalari
          .Select(x => new
              { 
                    date= x.date,
                    TotalUsageValue =  x.total_usage_T2, 
                    UsageType     = "T2" }
       )); 
    

    for usage type you juse need to add UsageType = "T2" in your new anonymous type as i did above this will do the task for you


    Than you should go for Concat method rather than Union method ..

    Example

     int[] ints1 = { 1, 2, 3 }; int[] ints2 = { 3, 4, 5 };
     IEnumerable<INT> union = ints1.Union(ints2);
     Console.WriteLine("Union");
     foreach (int num in union)
     {
        Console.Write("{0} ", num);
     }
     Console.WriteLine();
     IEnumerable<INT> concat = ints1.Concat(ints2);
     Console.WriteLine("Concat");
     foreach (int num in concat)
     {
        Console.Write("{0} ", num);
     } 
    

    output

    enter image description here

    Fact about Union and Concat

    The output shows that Concat() method just combine two enumerable collection to single one but doesn’t perform any operation/ process any element just return single enumerable collection with all element of two enumerable collections.

    Union() method return the enumerable collection by eliminating the duplicate i.e just return single element if the same element exists in both enumerable collection on which union is performed.

    Important point to Note

    • By this fact we can say that Concat() is faster than Union() because it doesn’t do any processing.

    • But if after combining two collection using Concat() having single collection with too many number of duplicate element and if you want to perform further operation on that created collection takes longer time than collection created using Union() method, because Union() eliminate duplicate and create collection with less elements.

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

Sidebar

Related Questions

I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
SQL query: SELECT ArticleCategories.Title AS Category, Articles.Title, Articles.[Content], Articles.Date FROM ArticleCategories INNER JOIN Articles
I want to SELECT a formatted date string from a datetime type in SQL
Sql: select distinct DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) as Date, (select count(*) from Raw_Mats
See the following SQL: SELECT M.username, count(*) as Total, date(status_date) as Date FROM com_result
There is sql statement select distinct create_date from articles Is it possibele to write
Original SQL query is this; SELECT id,post_title,post_date FROM wp_posts where id='1' When I retrieve
SQL : SELECT COUNT(usr.id) as `total_results` FROM users as usr LEFT JOIN profile as
SQL: select * from user where room_id not in (select id from rooms); what
I have the following SQL: SELECT * FROM [Database].dbo.[TagsPerItem] INNER JOIN [Database].dbo.[Tag] ON [Tag].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.