How to make a query to compare values in different columns?

M

Murph

I'm trying to figure out if there is a way to run a query that will compare
the values in column 5, based on the values in column 2. In column two the
values are a person ID number, and that number can be repeated on multiple
rows. The values in column 5 are dollar amounts. The dollar amounts for
each persons ID should be the same, but they all aren't. I want to run a
query that compares the dollar amounts in column 5 for each person's ID
number, and tells me if one of the dollar amounts is not equal. Is there a
way to do that? I'm still very new to databases, so I don't know much about
making these things.
 
J

John Viescas

SELECT MyTable.ID, MyTable.Dollars
FROM MyTable
INNER JOIN MyTable As MyTable_1
ON MyTable.ID = MyTable_1.ID
WHERE MyTable.Dollars <> MyTable_1.Dollars

To build this on the query grid, add two copies of the table in the top part
of the query and drag and drop the ID field from one to the other to create
the INNER JOIN. Add ID and Dollars from the first copy of the table and put
on the Criteria line:

<> MyTable_1.Dollars

... where MyTable is the name of the table and "Dollars" is the name of the
dollar field.

--
John Viescas, author
"Building Microsoft Access Applications"
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top