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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:41:40+00:00 2026-05-21T20:41:40+00:00

I have 2 tables which looks like this: ARTICLES TABLE: and the output should

  • 0

I have 2 tables which looks like this:

ARTICLES TABLE:

and the output should look like this:

enter image description here

How can I accomplish this using both sql query (i’m using sql server 2005) and using linq to sql query ?

BTW i’m using sql server 2005, asp.net with c# in Visual studio 2008.

Please help me

Thanks in anticipation

  • 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-05-21T20:41:41+00:00Added an answer on May 21, 2026 at 8:41 pm

    Update: Added Linq experssion that can be used if you require an OUTER join.


    INNER JOIN

    For an inner join ie. only get back the articles that have been bought at least once, you can use the following.

    LINQ 2 SQL

    from a in Articles
    join c in CustomersRecords on 
         a.Article_Name equals c.Article_Name 
    group a by new {a.SNo, a.Article_Name} into g
    select new 
           {
             SNo = g.Key.SNo, 
             Article_Name = g.Key.Article_Name, 
             Total_Items_Bought = g.Count()
           }
    

    The above translates to the following SQL

    SELECT COUNT(*) AS [Total_Items_Bought], [t0].[SNo], [t0].[Article_Name]
    FROM [Articles] AS [t0]
    INNER JOIN [CustomersRecord] AS [t1] ON [t0].[Article_Name] = [t1].[Article_Name]
    GROUP BY [t0].[SNo], [t0].[Article_Name]
    

    Which when cleaned-up a little gives you

    SELECT a.SNo, 
           a.Article_Name, 
           COUNT(*) AS Total_Items_Bought
      FROM Articles AS a
     INNER JOIN CustomersRecord AS c ON a.Article_Name = c.Article_Name
     GROUP BY a.SNo, a.Article_Name
    

    LEFT OUTER JOIN

    For a left outer join ie. get back all articles event those that have never been bought, you can use the following.

    LINQ 2 SQL

    from a in Articles
    join c in CustomersRecords on 
         a.Article_Name equals c.Article_Name into apc
    select new 
           {
             SNo = a.SNo, 
             Article_Name = a.Article_Name, 
             Total_Items_Bought = apc.Count()
           }
    

    This translates to the following SQL

     SELECT [t0].[SNo], [t0].[Article_Name], (
        SELECT COUNT(*)
        FROM [CustomersRecord] AS [t1]
        WHERE [t0].[Article_Name] = [t1].[Article_Name]
        ) AS [Total_Items_Bought]
     FROM [Articles] AS [t0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables which in simplified form look like this: Products( id: int,
I have a table with 3 columns which looks like this: File User Rating
Suppose I have an SQL table entitled Facility which looks like this: || FacilityID
I have a database table that looks like this: CREATE TABLE IF NOT EXISTS
I have an ASP.NET GridView which has columns that look like this: | Foo
I have two simple tables in Django which looks like: class Session(models.Model): id =
I have a nested hash table that looks like this: my %myhash = (
I have many tables in my database which are interrelated. I have a table
Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables:
This should be so simple, but I'm drawing a blank. I have two tables.

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.