(i want distinct in msaccess query)
i have two tables where my data is matching and repeating in datagridview im working on report plz help me
here is my simple join query
select Labortary.Test_Name,Labortary.Test_Charges,LabortaryTestRecord.[Total Amount]
from LabortaryTestRecord,Labortary
where LabortaryTestRecord.[PatientID]=Labortary.Patient_id
and LabortaryTestRecord.[PatientID]=34
You must add DISTINCT keyword:
SELECT DISTINCT Labortary.Test_Name,Labortary.Test_Charges,
LabortaryTestRecord.[Total Amount]
FROM LabortaryTestRecord,Labortary
WHERE LabortaryTestRecord.[PatientID]=Labortary.Patient_id
and LabortaryTestRecord.[PatientID]=34
Related
I am trying to create a statement that combines the following into three columns, BusinessEntityID, AveQuota and PctComm. I am having trouble joining, I keep getting a syntax error near join. Please help
SELECT BusinessEntityID, AVG (SalesQuota) as AveQuota
from [sales].[SalesPersonQuotaHistory]
group by BusinessEntityID
join
select (commissionpct * salesytd) as PctComm from sales.SalesPerson
The orginal question was to find each sales person's average Quote (from QuotaHistory, using aggregation) as a column called AvgQuota and join it with a column that calucalates the same sales person's commissions earnings YTD (from SalesPerson, uses two colums from a calculation).
You are missing the information on which column to join those tables in the the 'join' syntax. Please refer to join syntax here: https://www.w3schools.com/mysql/mysql_join.asp#:~:text=MySQL%20Joining%20Tables,a%20related%20column%20between%20them.&text=Notice%20that%20the%20%22CustomerID%22%20column,is%20the%20%22CustomerID%22%20column.
I have 2 tables, TableAPX and TableCRD. In both there are 3 columns PC, C, VAL
How can I write a query where I can find the differences between columns C and columns VAL. Column PC is the primary key and TableAPX is the source for TableCRD. The objective is to reconcile TableCRD to TableAPX
I am very new with Access.
Thanks
Select APX.C, CRD.C
From TableAPX APX
Inner Join TableCRD CRD on CRD.PC = APX.PC
Where Apx.C <> CRD.C OR Apx.Val <> Crd.Val
That's a generalized query, but it should give you an idea of what you might do.
In query design view you have both tables with a join on the PC fields. Then add all columns to display in the query.
You can run the query and see the fields side by side.
Then to have the query highlight differing values - you need to create a calculated field; this is done with an alias name followed by a formula. In this case you might do
Cdiff: iif(Apx.C=CRD.C,0,1)
this iif will display a 0 when they are the same and a 1 when they differ
To start off, I would classify myself as a relatively new MS Access user (had to teach myself for work) and have encountered a problem. I have a cross-tab query (code displayed below) with the resulting datasheet resembling the desired results picture attached (excluding the % of total column). I would like to be able to reference the Sum total from the Total Spend row in all three of the % of total columns. This has proven to be a harder task than I initially had thought.
TRANSFORM Sum(Table1.Amount) AS SumOfAmount
SELECT tblSpendCat.SPEND_CAT, tblSpendCat.SPEND_DESC, Sum(Table1.Amount) AS Totals
FROM tblSpendCat INNER JOIN (tblType INNER JOIN (tblOrg INNER JOIN Table1 ON tblOrg.ID = Table1.tblORG_ID) ON tblType.ID = Table1.tblType_ID) ON tblSpendCat.ID = Table1.tblSpendCat_ID
WHERE (((tblSpendCat.SPEND_CAT)="Total_Spend" Or (tblSpendCat.SPEND_CAT)="Supplies" Or (tblSpendCat.SPEND_CAT)="Other Costs" Or (tblSpendCat.SPEND_CAT)="Misc") AND ((Table1.mnth)>"April") AND ((tblOrg.Org)="Org1" Or (tblOrg.Org)="Org2" Or (tblOrg.Org)="Org3" Or (tblOrg.Org)="Org4" Or (tblOrg.Org)="Org5" Or (tblOrg.Org)="Org6" Or (tblOrg.Org)="Org7"))
GROUP BY tblSpendCat.SPEND_CAT, tblSpendCat.SPEND_DESC
PIVOT Table1.mnth;
What I have tried:
I queried the specific Total Spend value in a separate stand-alone query and attempted to reference it in the main cross-tab query in a new expression field: results returned from the separate, stand-alone query :
Tried referencing the calculated value directly from the main cross-tab query (the same main cross-tab query referenced in this post) in a new expression field in the same main cross-tab query
Desired Results:
Thanks in advance for any help!
Best,
James
Hi i need your help on MS Access Database. I have two tables,tblExpense with three Columns(ExpenseID,ExpenseDate,Status) And tblExpenseDetails(ExpenseID,RefNo,Amount,Purpose).
Which Select Statement should i use if i want to get the Status from tblexpense using the RefNo from tblExpenseDetails?
{SELECT tblexpenseDetails.RefNo,tblexpense.Status,tblexpenses.ExpenseDate FROM tblExpense INNER JOIN tblexpenseDeatils ON tblexpensedetails.ExpenseID=tblexpenses.ExpenseID WHERE tblexpenseDetails.RefNo=?;
Used That and it worked any other ideas are still welcome.
I´m trying to update a third table with the result of a select query - I know how to do this on mysql but access makes insane :)
I have the following statement:
UPDATE ceilings LEFT JOIN
(SELECT ceiling_number AS cc, Count(type=3) AS st FROM ceiling INNER JOIN materials ON ceiling.material_number = materials.id GROUP BY ceiling.ceiling_number) AS q
ON q.cc=ceilings.ceilingid SET ceilings.stairs = q.st;
but it does not update tables and when I want to execute the statement i get the error:
"Operation must use an updateable query"
Would be great if someone could help me with this.
Update queries won't work with several types of other queries, including things like Group by, Totals, CrossTabs, or queries with left or right joins (in combination with inner joins).
There are a couple of solutions around this problem depending on your comfort level with Access and VBA.
Create a temporary table first. Write the results of your query to the temporary table, then use the temporary table to update the results of your ceilings table.
Use VBA to create and store the values of the non-update-able query, then using recordsets, loop thru your records and update the values in your ceilings table.