I’m trying to fetch data from two tables however it doesn’t seem to be pulling all records that match the criteria.
This is my query:
SELECT Parts."Part Number",Parts."Description",Parts."Location",Parts."Qty In Stock",Parts."LastCost",Parts."Cost Price",Parts."Retail Price",Transact."Type"
FROM Transact
INNER JOIN Parts
ON Transact."PartNumber"=Parts."Part Number"
WHERE Transact.Type = 'Non-stock Purch'
I’m trying to pull every record that has ‘Non-stock purch’ against it and then pull the description of that part from the parts database, hence why I have included the ‘Description’, ‘Cost’, ‘Last Cost’ etc.
Am I doing something wrong in the query that means it’s not going to fetch all of the needed information, if I run:
select * from transact x
where x.Type = 'Non-stock Purch'
order by x.PartNumber
This will return 268 records, my previous query should return the same number but only actually returns 111, I know they exist within the other table as they have to (I have also checked (just in case something went wrong)).
Also if I’m writing these queries incorrectly or the formatting isn’t correct, let me know!
Thanks.
There’s a possibility that the Parts table may not have matching records for records in the Transact table. You’re doing an INNER JOIN; if there’s no record in Parts that has a part number that appears in a record in Transact, no row will be returned.
If you want all the records in Transact, and the data from Parts if it exists, you might do a LEFT JOIN; all the columns from Parts would be null in the result if there isn’t a match.