Re: Tough query (for me)



Thom wrote:
I have a table of books with the following fields:
ID (unique)
Author
Title
Sold (y/n)
Overstock (y/n)
I want to write a query that will show me, for each book marked sold,
if there are any in overstock.
My query is:
SELECT Table_02.Author, Table_02.Title, Table_01.Index AS SoldIndex,
Table_02.Index AS Remain_Index, Table_02.OverStock
FROM Books AS Table_01, Books AS Table_02
WHERE
Table_02.Author=Table_01.Author And
Table_02.Title=Table_01.Title And
Table_01.Sold=True And
Table_02.Sold=False

but it gives me the sold book as many times as there are overstock
books and not at all if there are no overstock books.

I will be doing the query in vb but that is not my problem . . .
My problem is writing the query in the first place.
Thanks
Thom W.
;
1. Never ask a query/database-related question without telling us the type
and version of database you are using. It is almost always relevant.

2. Show us a few rows of sample data (in tabular form) and indicate the rows
(again in tabular form) you want the query to retrieve. It also helps to
show (again in tabular form) the results you are getting from your latest
attempt and describe what is wrong with those results.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


.



Relevant Pages

  • Re: abstraction of table relationships
    ... > the relationships between tables to make queries shorter. ... He gave the example of Books and Authors. ... > be better if one could query all books by a given author ... > done with natural join in mind. ...
    (comp.databases.theory)
  • Re: Form Advice Relating to Queries
    ... books, Mastering Access 2002 Premium Edition, Access InsideOut 2002 by Helen ... For more complex queries, use vba programming..... ... I haven't quite worked out how to use the Query Builder via ... ... The form's RecordSource property is a string. ...
    (microsoft.public.access.forms)
  • Re: Return to form if query unmatched
    ... sends the number to he main BOOKS form, which is based on the following query: ... FROM BOOKS ... If it doesn't pop up a message and set Cancel = True. ... Doug Steele, Microsoft Access MVP ...
    (microsoft.public.access.queries)
  • RE: Only Return Lastest Date From Records
    ... Yes it is SQL and it will show all the books in the result. ... query open the query designer in the usual way, but don't add any tables, ... represented in the Transactions table with its latest Date In value. ...
    (microsoft.public.access.queries)
  • Re: Return to form if query unmatched
    ... sends the number to he main BOOKS form, which is based on the following query: ... FROM BOOKS ... Dim MyRecCount As Long ... If it doesn't pop up a message and set Cancel = True. ...
    (microsoft.public.access.queries)