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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:40:01+00:00 2026-06-03T22:40:01+00:00

I have SQL table that holds buyers personal data such as FirstName, LastName, OGCard;

  • 0

I have SQL table that holds buyers personal data such as FirstName, LastName, OGCard;
OGCard – field that indicates clients personal card number.

Next I have table called Cards which contains data about ten items that were purchased in the following format: OGCard, Item1ID,…,Item10ID,Item1Quantity,…,Item10Quantity

And in table Items I got such structure ItemID, ItemName

I want to get all purchases from CardNumber

I think i should do something like that

SELECT Buyers.FirstName, Items.Name, Cards.Item1Quantity
FROM Buyers
INNER JOIN Cards ON Buyers.OGCard=Cards.OGCard
INNER JOIN Items ON Cards.Item1ID=Items.ItemName
WHERE OGCard=13451

In this way I can see the name of first item and it’s quantity. However i cannot perform the same join to column Item2ID, and so on. Could you suggest me some solution?

  • 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-03T22:40:03+00:00Added an answer on June 3, 2026 at 10:40 pm

    It’s possible to join the same table twice by using aliases:

    SELECT
        Buyers.FirstName,
        Items1.Name, Cards.Item1Quantity,
        Items2.Name, Cards.Item2Quantity,
        Items3.Name, Cards.Item3Quantity,
        Items4.Name, Cards.Item4Quantity
    FROM Buyers
    INNER JOIN Cards ON Buyers.OGCard=Cards.OGCard
    INNER JOIN Items AS Items1 ON Cards.Item1ID=Items.ItemName
    INNER JOIN Items AS Items2 ON Cards.Item2ID=Items.ItemName
    INNER JOIN Items AS Items3 ON Cards.Item3ID=Items.ItemName
    INNER JOIN Items AS Items4 ON Cards.Item4ID=Items.ItemName
    WHERE OGCard=13451
    

    If some of the Items_n_IDs can be missing, you could use a LEFT JOIN instead of an INNER JOIN so that you still get the results for the values that are present.

    However I’d strongly recommend you to normalize your database rather than going with this approach.

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

Sidebar

Related Questions

I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a sql table of payroll data that has wage rates and effective
I have a SQL database that has a table with a field set to
I have a column called THE_VALUE in a table TABLE_A , that holds data
I have a database table that holds customer data with several million rows in
Here is what i have: a SQL CE database, that holds this Category table,
I have a table in my SQL Server DB that holds auditing information for
I have a field in an Azure table that holds date times in string
I have an sql table of PlayerTrial that holds, well, player trials. ---PlayerTrials Basic
I have an sql server 2008 db table that holds links to articles. My

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.