Merging 2 tables from two different datasets SQL Using Google BigQuery - sql

Doing a project and have been stuck.
The two datasets are called mimic3_demo (c) and mimic3_demo_omop (m).
I need to merge one table from c to one table from m. The first table from dataset c is PATIENTS and the second table from dataset m is condition_occurrence.
I'd like to join them on SUBJECT_ID from database c table PATIENTS and person_id from database m table condition_occurrence.
This is the simple code I've used so far but it keeps saying "there is no data to display"
I am using Google Big Query to code this was what the course provided us.
Select *
from mimic3_demo.dbo.PATIENTS c
Join mimic3_demo_omop.dbo.condition_occurrence m on c.SUBJECT_ID = m.person_id
Please help! Thanks.

Related

SQL join using EF Core

I am a bit stuck and would appreciate some help.
I have the following data structure as shown in the image below.
So I want to link C and D basically apply the list to list. And if possible how would I do this in ef core. I did try a different query
SELECT * FROM A a
JOIN B b on a.PKA= B.PKB
But I only get the multiplication of list every record from table B got a pair for every record of table A. One more question if records in table C don't have the same number of record in table D it values should be null

Parent child relationship Join tables in oracle sql

I have a requirement below.
Now I have to get output like below
How can this be achieved ?
I have written the below SQL but parent_position_id is coming, not parent_position_code
select
hapf.position_code,
pphf.parent_position_id
from
hr_all_positions_f hapf, PER_POSITION_HIERARCHY_F pphf
where
hapf.position_id = pphf.position_id
Should I write a sub query? How should I proceed ?
This is Oracle SQL
Thanks,
Shivam
Noone ever said you could only join a table in once:
select
chi.position_code,
par.position_code as parent_position_code
from
hr_all_positions_f hapf
INNER JOIN PER_POSITION_HIERARCHY_F chi on hapf.position_id = chi.position_id
INNER JOIN PER_POSITION_HIERARCHY_F par on hapf.parent_position_id = par.position_id
Bear it in mind; I see people coming to thinking all the time that they can only join a table once. If one table decodes a value in 3 different columns, then you sure can join that same table in 3 times... Imagine if it were an address table, and a Student had a HomeAddressId, WorkAddressId and StudyAddressId, and the Address table held all these addresses - you'd join the addresses table to the Student table 3 times to get all the data..

SQL Self Join - one to many - with dates

I have the following two tables in sqlite:
SQL Tables
The table "Performance Indicator Table" gets populated each day with 'PerformanceIndicator' values from previous day against each site. Each site is connected to many other sites termed as site's neighbors. For instance, site A may have site C and D as its neighbors. Similarly site C can have B and itself as neighbors. These neighbor relations are defined in a mostly static "Neighbor Table".
I need to come up with a single view, joining the two tables such that we have:
Resultant Table
Please help me in coming up with the required SQL. I thought of the following:
select neighbors.site, neighbors.neighbor, PI_Table.*
from neighbors
inner join PI_Table
on neighbors.neighbor = PI_Table.site;
I am using Sqliteman to process the query and this gives me some kind of result. But exporting results in Sqliteman not responding. This may be due to number of rows. Number of rows should be:
Number of rows in resultant view
Please let me know if it seems okay and sorry for not being able to have the images in-line.
select neighbors.site, neighbors.neighbor,
p1.*, p2.*,
performance(..)
from neighbors
inner join PI_Table p1
on neighbors.site = p1.site;
inner join PI_Table p2
on neighbors.neighbor = p2.site;
AND p1.date = p2.date

One to Many join in access

I have tow tables, one collar table with drillhole unique numbers with their x,y,z values and second table with drillhole numbers with geology information and one drillhole can have many geology information based on drillhole depth. I want to join two table. Would you please how can I join these two table in ms access. I want all the data from drillhole collar table and only matching data from geology table. I am trying but could not succeed. Please advise.enter image description here
Two Tables
If you want all data from a master table (drillhole collar table) plus matching data from a child table (geology table), this is achieved by using a LEFT JOIN query. Adapt this example by replacing the table and column names with ones that you need from your database:
SELECT d.*, g.*
FROM Drillhole d
LEFT JOIN Geology g ON d.Hole_ID = g.Hole_ID

Query patient ID #s from an Excel 2007 list?

I'm using an Access Database that is designed relationally. I have a list of patient IDs in an Excel spreadsheet that I imported and made into a table in Access named importedPatients. There is a related table named Counties that is a one to many relationship for the main Patients table. How can I use the patientIDs present in the importedPatients table to quickly query out information in the related Counties table? Is there an idiomatic way to tackle this?
This diagram can give you an idea:
and here is SQL generated by the Designer:
SELECT importedPatients.ImportedPatientID, Patients.PatientName, Counties.County
FROM (Counties INNER JOIN Patients ON Counties.CountyID = Patients.CountyID)
INNER JOIN importedPatients ON Patients.PatientID = importedPatients.ImportedPatientID
This will give you county information for each record in importedPatients:
SELECT counties.*
FROM counties INNER JOIN (importedpatients INNER JOIN patients ON
importedpatients.patientid = patients.patientID) ON
counties.countyid = patients.countyid