Results 1 to 6 of 6
  1. #1
    Auto is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    60

    Item without price, or duplicate price

    hi everyone,



    i have a table called Books, in that table there is column ChapterName, Auther, ITEM, Price.
    each book has a item number, and each book has a few records with the same data, just the first column is diffrent where its the ChapterName, each book has a price, but only once, meaning in the first record of each book it will be a price in the column price

    now i want a report where i can get which book dont have a price at all, and which book has more than once a price, how can i do that?
    i am breaking my head all day with it, and i cant come up with anything.

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    This will get items with more than one non-Null price:
    Code:
    Select ITEM, Count(Price)
    FROM Books
    GROUP BY ITEM
    Having Count(Price) > 1;
    This will get items with no non-null prices.
    Code:
    Select B1.ITEM
    FROM Books AS B1
    WHERE B1.ITEM NOT IN 
       (
       SELECT ITEM
       FROM Books AS B2
       GROUP BY ITEM
       Having Count(B2.Price) > 0
       );

  3. #3
    Auto is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    60
    Brilliant! this is exactly what i want, thank you so much, WOW

  4. #4
    Auto is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    60
    the first SQL for more than one-null price worked like a charm,
    but this code hangs down and freeze

    This will get items with no non-null prices.
    Code:
    Select B1.ITEM
    FROM Books AS B1
    WHERE B1.ITEM NOT IN 
       (
       SELECT ITEM
       FROM Books AS B2
       GROUP BY ITEM
       Having Count(B2.Price) > 0
       );
    [/QUOTE]

  5. #5
    Auto is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    60
    ok, here is what i did, i used the same SQL for non null price, just changed <

    Select ITEM, Count(Price)
    FROM BooksGROUP BY ITEM Having Count(Price) < 1;
    and its doing the purpose!

  6. #6
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Glad you go what you needed. Not sure what hung the system about that second one.

    This would work too
    Code:
    Select B1.ITEM
    FROM Books AS B1
    WHERE B1.ITEM NOT IN 
        (
        SELECT ITEM
        FROM Books AS B2
        WHERE B2.Price >= 0
        );

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Select the last price in a day
    By 12345678 in forum Queries
    Replies: 1
    Last Post: 05-11-2012, 02:08 PM
  2. Set Up Price Tables
    By Jo22 in forum Database Design
    Replies: 5
    Last Post: 02-12-2012, 12:34 PM
  3. Replies: 5
    Last Post: 07-29-2011, 12:55 AM
  4. Overall price paid
    By MFS in forum Reports
    Replies: 1
    Last Post: 07-02-2011, 07:19 PM
  5. Look up price
    By matt4003 in forum Queries
    Replies: 7
    Last Post: 12-28-2009, 02:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums