×
We value your feedback! Please click here to access our 2024 Client Survey.
The survey will remain open until November 1st. Your perspective will help guide our product/service planning and goals for the upcoming year and beyond!

study queries on datasets with additional keys

Study Forum (Inactive)
study queries on datasets with additional keys wonjong.moon  2008-02-26 12:28
Status: Closed
 
I tried to query two tables Extracted_RNA and Extracted_RNA_Use_Log in Labkey
I used the following query at
study queries >

SELECT Extracted_RNA.ParticipantId,
Extracted_RNA.ExtractionID,
Extracted_RNA.SampleBarcode,
Extracted_RNA.BioanalyzerResultsPDF,
Extracted_RNA.A320,
Extracted_RNA.Notes,
Extracted_RNA.ParticipantVisit.Extracted_RNA_Use_Log.PurposeofUse
FROM Extracted_RNA

It did not work

Query 'RNA_Extraction_Worksheet' has errors
Error on line 25:Unknown field Extracted_RNA.ParticipantVisit.Extracted_RNA_Use_Log.PurposeofUse

But there was the field 'PurposeofUse'.
I attached the screen shot, datasets, and schemas.
I think Labkey could not find the field because 'Extracted_RNA_Use_Log' had an additional key 'ExtractionUseID'
Also Labkey did not display 'Extracted_RNA_Use_Log' under participantId in Customize Grid View


Is it right? How can I join or query datasets with additional keys?
 
 
marki responded:  2008-02-26 14:50
Hi Wonjong,

I think the problem here is due to the "additional key" feature. If an additional key is defined on a dataset, you can use the standard "customize view" ui to start with that dataset and join to any other dataset *without* an additonal key. However, I'm guessing that you have additional keys on *both* datasets. The LabKey system doesn't know that these keys are actually the same and should be joined together. So you have two options

A) Don't use additional keys. Instead change participantid or sequencenum to encode more information. Whether this is feasible depends on whether that additional information can be used across all datasets. I'm guessing this isn't an adequate solution, but it is easy. If you choose to do this you should know there is currently length limit on participantid (16 chars -- to be upped in next version).

B) Better, you can use the query service to create a "grid report" that joins this data together manually using SQL. Due to a bug in the query service that we'll look at, you actually have to create 2 queries, one as an Alias for one of your datasets, the other query actually does the join. Here's how you would do it.
  
1) Get to the Query service. Click "Manage Reports and Views", Click "New Grid View", Click "Modify Dataset List (Advanced)". This will allow you to create new queries. I'm assuming you want to start with all the rows from the Extracted_RNA table. You could modify these steps to start with the other table

2) Create Alias Query.
   2.1 Click "Create New Query"
   2.2 Fill in the form like this.
What do you want to call the new query? : Extracted_RNA_Alias
Which query/table do you want this to be based on? : Extracted_RNA
   2.3 Click Create And Design
   2.4 Click Save (It already includes all the fields in the base table)

3) Create Join Query
   3.1) Click "study queries" link in the "crumb trail" to get back to the list of queries
   3.2) Create New Query
   3.3) Fill in the form like this.
What do you want to call the new query? : Extracted_RNA_All
Which query/table do you want this to be based on? : Extracted_RNA_Alias (This is the query you just created)
   3.4) Click "Create and Edit SQL" (you'll need to create the join by hand)
   3.5) You'll see the SQL to select all fields in the Alias table. You'll need to edit the sql to include a join in the other table. This should work to join to the Use_Log on SampleBarcode (I'm just guessing that's what you want -- you cold also do a multi-column join):

SELECT Extracted_RNA_Alias.ParticipantId,
Extracted_RNA_Alias.sourcelsid,
Extracted_RNA_Alias.SequenceNum,
Extracted_RNA_Alias.ExtractionID,
Extracted_RNA_Alias.SampleBarcode,
Extracted_RNA_Alias.PatientID,
Extracted_RNA_Alias.SampleDate,
Extracted_RNA_Alias.ExtractionDate,
Extracted_RNA_Alias.ProtocolName,
Extracted_RNA_Alias.A260,
Extracted_RNA_Alias.A280,
Extracted_RNA_Alias.A260A280,
Extracted_RNA_Alias.A260A230,
Extracted_RNA_Alias.SpecDilution,
Extracted_RNA_Alias.Concentration,
Extracted_RNA_Alias.VolumeLeft,
Extracted_RNA_Alias.MassLeft,
Extracted_RNA_Alias.BoxName,
Extracted_RNA_Alias.Notebook,
Extracted_RNA_Alias.Pages,
Extracted_RNA_Alias.LabelText,
Extracted_RNA_Alias.LabelFile,
Extracted_RNA_Alias.BioanalyzerFile,
Extracted_RNA_Alias.BioanalyzerResultsPDF,
Extracted_RNA_Alias.A320,
Extracted_RNA_Alias.Notes,
Extracted_RNA_Use_Log.PurposeofUse,
Extracted_RNA_Use_Log.VolUsed,
Extracted_RNA_Use_Log.MassUsed,
Extracted_RNA_Use_Log.VolLeft,
Extracted_RNA_Use_Log.ConcAfter,
Extracted_RNA_Use_Log."User",
Extracted_RNA_Use_Log.Notes As Log_Notes
FROM Extracted_RNA_Alias JOIN Extracted_RNA_Use_Log ON
Extracted_RNA_Alias.SampleBarCode=Extracted_RNA_Use_Log.SampleBarCode

Now you can save this query.

To have this query show up in "Reports" list, create a new Grid Report over the new Extracted_RNA_All query
 
wonjong.moon responded:  2008-02-27 09:03
Thanks a lot. That works great.