Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Short Introduction to Analyzing Biological Data Using Relational Databases Part III: Writing Simple (Single Table) Queries to Access Relational Data.

Similar presentations


Presentation on theme: "A Short Introduction to Analyzing Biological Data Using Relational Databases Part III: Writing Simple (Single Table) Queries to Access Relational Data."— Presentation transcript:

1 A Short Introduction to Analyzing Biological Data Using Relational Databases
Part III: Writing Simple (Single Table) Queries to Access Relational Data Alex Ropelewski Pittsburgh Supercomputing Center National Resource for Biomedical Supercomputing Bienvenido Vélez University of Puerto Rico at Mayaguez Department of Electrical and Computer Engineering

2

3 Learning Objectives Using SQL SELECT statement to:
Select which attributes to show in a result Select which rows to show in a result Using UPDATE to modify rows Using DELETE to remove rows Using logical operators (AND, OR and NOT) to form more complex selections of rows Using INTO clause to store result rows into new database tables

4 The language of relational databases
SQL The language of relational databases Data definition/schema creation Implements relational algebra operations Data manipulation Insertion Manipulation Updates Removals A standard (ISO) since 1987

5 An Improved Relational Database Design
Sequences Accession Description Species P14555 Group IIA Phospholipase A2 Human P81479 Phospholipase A2 isozyme IV Indian Green Tree Viper P00623 Phospholipase A2 Eastern Diamondback Rattlesnake Matches Accession RunNum eValue P14555 1 4.18 E-32 P81479 2 2.68 E-52 3.47 E-33 1.20 E-54 P00623 1.21 E-08 Runs RunNum Date Matrix 1 7/21/07 Pam70 2 7/20/07 Blosom80

6 SQL: SELECT Statement Selects attributes
SELECT Accession, Description, Species FROM Sequences In this context since we are selecting all attributes in the table. We could use the wildcard character * instead of listing the individual attribute names: SELECT * FROM Sequences Sequences Accession Description Species P14555 Group IIA Phospholipase A2 Human P81479 Phospholipase A2 isozyme IV Indian Green Tree Viper P00623 Phospholipase A2 Eastern Diamondback Rattlesnake

7 Used to filter tuples with certain attribute values
SQL: WHERE Clause Used to filter tuples with certain attribute values Used in many SQL Statements, including SELECT SELECT * FROM Sequences WHERE Species=’Human’ Sequences Accession Description Species P14555 Group IIA Phospholipase A2 Human

8 Used to order data by attribute values
SQL: ORDER BY Clause Used to order data by attribute values Used in many SQL Statements, including SELECT SELECT * FROM Sequences ORDER BY Species Sequences Accession Description Species P00623 Phospholipase A2 Eastern Diamondback Rattlesnake P14555 Group IIA Phospholipase A2 Human P81479 Phospholipase A2 isozyme IV Indian Green Tree Viper

9 SQL: UPDATE Statement Revises table data
Sequences (before UPDATE) Accession Description Species P14555 Group IIA Phospholipase A2 Human UPDATE Sequences SET Species=’Homo Sapiens’ WHERE Accession=’P14555’ Sequences (after UPDATE) Accession Description Species P14555 Group IIA Phospholipase A2 Homo Sapiens

10 Removes table data – Be Careful!
SQL: DELETE Statement Removes table data – Be Careful! Sequences (before DELETE) Accession Description Species P14555 Group IIA Phospholipase A2 Human P81479 Phospholipase A2 isozyme IV Indian Green Tree Viper P00623 Phospholipase A2 Eastern Diamondback Rattlesnake DELETE FROM Sequences WHERE Accession=’P14555’ Sequences (after DELETE) Accession Description Species P81479 Phospholipase A2 isozyme IV Indian Green Tree Viper P00623 Phospholipase A2 Eastern Diamondback Rattlesnake

11 Used in many SQL Statements One of two conditions must be met
SQL: OR operator Used in many SQL Statements One of two conditions must be met SELECT * FROM Matches WHERE Accession=’P14555’ OR Accession=’P00623’ Matches Select Result Accession RunNum eValue P14555 1 4.18 E-32 P81479 2 2.68 -E52 3.47 E-33 1.20 E-54 P00623 1.21 E-08 Accession RunNum eValue P14555 1 4.18 E-32 2 3.47 E-33 P00623 1.21 E-08

12 Used in many SQL Statement Two of two conditions must be met
SQL: AND operator Used in many SQL Statement Two of two conditions must be met SELECT * FROM Matches WHERE Accession=’P14555’ AND RunNum=’1’ Matches Select Result Accession RunNum eValue P14555 1 4.18 E-32 P81479 2 2.68 -E52 3.47 E-33 1.20 E-54 P00623 1.21 E-08 Accession RunNum eValue P14555 1 4.18 E-32

13 Used in many SQL Statement Negation of condition
SQL: NOT operator Used in many SQL Statement Negation of condition SELECT * FROM Matches WHERE NOT Accession=’P14555’ Matches Select Result Accession RunNum eValue P14555 1 4.18 E-32 P81479 2 2.68 -E52 3.47 E-33 1.20 E-54 P00623 1.21 E-08 Accession RunNum eValue P81479 2 2.68 -E52 1 1.20 E-54 P00623 1.21 E-08

14 Used to clarify order of operations
SQL: Parenthesis Used to clarify order of operations SELECT * FROM Matches WHERE ((Accession=’P14555’) OR (Accession=’P81479’)) AND RunNum=’2’ Matches Select Result Accession RunNum eValue P14555 1 4.18 E-32 P81479 2 2.68 -E52 3.47 E-33 1.20 E-54 P00623 1.21 E-08 Accession RunNum eValue P14555 2 3.47 E-33 P81479 2.68 E-52

15 Used to store results in new tables
SQL: INTO Used to store results in new tables SELECT * INTO GoodMatches FROM Matches WHERE (eValue >= 1.0E-10) Matches GoodMatches Table Accession RunNum eValue P14555 1 4.18 E-32 P81479 2 2.68 -E52 3.47 E-33 1.20 E-54 P00623 1.21 E-08 Accession RunNum eValue P00623 2 1.21 E-08

16 Key Concepts SQL’s SELECT statement can be used to select which attibutes should appear in a result SQL’s SELECT statement can be used to select which rows should appear in a result using the WHERE clause SQL’s UPDATE statement can be used to modify rows SQL’s DELETE statement can be used to remove rows Logical operators can be used to form complex logical conditions for selecting which rows to show in a result The INTO clause can be used to store results into a new table in the database


Download ppt "A Short Introduction to Analyzing Biological Data Using Relational Databases Part III: Writing Simple (Single Table) Queries to Access Relational Data."

Similar presentations


Ads by Google