

Note the WHERE clause in this query which contains two predicates to ensure that: i.) source and joined table rows are not cross-joined between patients (imagine cross-joining an entire 10,000-row-table against itself!) and ii.) results for the same date-time (within patients only thanks the first WHERE predicate) are not resulted (since the difference would be a constant - i.e., zero - which is unlikely to be useful for this specific example).įull disclosure: the WHERE predicates nullify the ultimate effect of the CROSS JOIN since there is no longer a pure cross-product of the two input tables (i.e., the table product doesn’t have n x m rows).

The table product is all within-patient comparisons of the patient’s serum creatinine values, which can be used for determining whether any significant changes occurred (e.g., increases of ≥ 0.5 mg/dL). The results from the above query are shown in Figure 4.4. SELECT rslts.pat_id, rslts.pat_enc_csn_id, rslts.creatinine, rslts.creatinine_dttm, rslts_2.creatinine, rslts_2.creatinine_dttm, rslts_2.creatinine - rslts.creatinine AS scr_difference FROM results AS rslts CROSS JOIN results AS rslts_2 WHERE rslts.pat_id = rslts_2.pat_id AND rslts.creatinine_dttm rslts_2.creatinine_dttm 4.6 Clauses of the SELECT statement: A Multi-table Example.4 Basic Syntax (Multi-table Query): JOIN Operations.3.3.2 Uniqueness: Candidate Key or Minimal Superkey.Relational Database Schemas: The Second “s”.3 Relational Database Schemas: Tables, Rows, Columns, and Keys.2.3 SQL Language Elements: A Basic Example Continued.2.2 Clauses of the SELECT statement: A Basic Example.2.1 SELECT statement and Logical Processing Order.2 Basic Syntax (Single-table Query): Clauses and Language Elements.1.4.3 Basic Environmental Customizations.1.4.2 Connect to Relational Databases: Clarity and Warehouse.1.4.1 Connect to Database Engine Server: Claritysnap.1.4 Microsoft SQL Server Management Studio (SSMS): Getting Started.
