dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] Complex SQL statement

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    50

    Resolved [RESOLVED] Complex SQL statement

    I have 5 tables and i want to display all the receipt details and the details of the chosen item of a specific chosen item by the user that have sold ( so all the receipts for example ItemID 1 that occur in the "ReceiptItems" table), could anyone help me with what the statement should look like as i have been struggling.

    Any help appreciated

    Here are my tables

    ================
    ReceiptItemLink ReceiptID ItemID
    ================
    1 1 1


    ================
    ReceiptID CustomerID ReceiptDate ReceiptTime
    ================
    1 2 13/09/2018 15:22:12


    ================
    ItemID ItemName
    ================
    1 product

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Complex SQL statement

    This question has nothing to do with VB.NET. Questions about SQL belong in the Database Development forum. I have asked the mods to move this thread.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Complex SQL statement

    First you say that you have 5 tables and then you show 3 tables. That's confusing. It sounds like all you need is to use INNER JOINS on the three tables you have displayed. If you don't know how to perform an inner join, you should do some reading on the subject and then make an attempt. Do it in the database itself first and then only copy the SQL code into your application when it is working. If it doesn't work, post back here and show us what you did and tell us what happened.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    50

    Re: Complex SQL statement

    It is because these are the only 3 tables i am interested in, i shall do some reading and make an attempt

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Complex SQL statement

    Quote Originally Posted by snoopyd View Post
    It is because these are the only 3 tables i am interested in
    In that case, mentioning that you have 5 tables is only going to distract from the issue at hand. Whether you have 3, 5, 25 or 2000 tables doesn't really matter if you are only interested in using 3. When I read "5" and saw three, I was wondering whether I was missing something or you had forgotten to include something. Context can be good but relevance is important. If you want to say that you have 5 tables, at least stipulate that you are only interested in 3 of them for the current problem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,349

    Re: Complex SQL statement

    Thread moved to the 'Database Development' forum - which is where you should always post SQL questions (while SQL can be used in VB.Net, it is certainly not specific to VB.Net)

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    50

    Cool Re: Complex SQL statement

    Quote Originally Posted by jmcilhinney View Post
    In that case, mentioning that you have 5 tables is only going to distract from the issue at hand. Whether you have 3, 5, 25 or 2000 tables doesn't really matter if you are only interested in using 3. When I read "5" and saw three, I was wondering whether I was missing something or you had forgotten to include something. Context can be good but relevance is important. If you want to say that you have 5 tables, at least stipulate that you are only interested in 3 of them for the current problem.
    Instead of using inner joins i used a fourth table in my SQl statement and managed to solve the issue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width