What I'm hoping to do is write a query which will list all clients who have a MMSE score at Week 26, which is greater than the MMSE at Week 0. Can anyone help?
SELECT a.Clientnumber
FROM Table_client a
WHERE a.weeknubmer=26
and a.mmsescore > ( select b.mmsescore from Table_client b where b.weeknumber=0 and a.clientnumber=b.clientnumber);
That won't work as the 2 tables are ClientInfo & Cognitive. Cognitive contains the fields ClientNumber, WeekNumber and MMSEScore.
The ClientInfo table doesn't contain a WeekNumber field, only ClientNumber. It is a one to many relationship. Any help would be greatly appreciated.
make a new query,
change the table name in the select statement postet above. paste this into the sql-view of the new query.
if you want to add data from your client info table. change to the edit-view . add the client info table to the view .
and make a left join from the client info table to the cognitive table.
Just pasted your code and made up the tables and it worked fine. I assumed that week number was numeric, changing it to text gave a data type mismatch error so you may want to check this.
SELECT Cognitive.[MMSE Score]
FROM ClientInfo LEFT JOIN Cognitive ON ClientInfo.[Client Number] = Cognitive.[Client Number]
WHERE Cognitive.[Week Number]=0 AND [ClientInfo].[Client Number]=[Cognitive].[Client Number];
separately and it returns more than one record. There must be a crossjoin being created between the 2 tables, but I don't know how to fix this. Can anyone help??
select first(Cognitive.[MMSE Score])
FROM ClientInfo LEFT JOIN Cognitive ON ClientInfo.[Client Number] = Cognitive.[Client Number]
WHERE Cognitive.[Week Number]=0 AND [ClientInfo].[Client Number]=[Cognitive].[Client Number];
will give you the first value, but I am not sure if it is what you want.
Could you determine which of the records returned , is the one you want to get?
Thanks guys... turned out my colleague ran an append query on the Cognitive table causing there to be duplicate records. Got it working now... thanks for all your help... much appreciated.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.