Professional Documents
Culture Documents
It will select all coloumns. When (*) is used, it will select all in your database instead
2. What is the purpose of a JOIN Clause? How many JOIN clauses are there?
Join clause is used to merge Rows from two or more than two tables utilizing the
relation between them, its purpose is to fetch data from multiple tables in a single query,
1)INNER JOIN: Returns records that have matching values in both tables
2)LEFT JOIN: Returns all records from the left table, and the matched records
3)RIGHT JOIN: Returns all records from the left table, and the matched records
4)FULL JOIN: Returns all records when there is a match in either left or right table,
RIGHT JOIN: It includes all the Element from The Right Table and all the matched
LEFT JOIN: It includes all the Element from The Left Table and all the matched
SQL WHERE Statement is used to filter records. It is used to extract only those
WHERE Country='Mexico';
On the other hand, SQL Group By statement groups rows that have the same
values into summary rows, like "find the number of customers in each country".
(COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns.
4. What is the order that the SQL processor will evaluate SQL
The order that the SQL processor will evaluate the SQL statement is in this
following order
1. FROM
2. WHERE
3. GROUP BY
4. HAVING
5. SELECT
6. DISTINCT
7. ORDER BY
8. LIMIT/OFFSET
The difference is that it is referred as the logical processing order, and even though
you write the square statements in a selected order, the square processor will reorganize
and optimize the execution and it is primarily based on the database's internal common
5. In the textbook, there are some 'keys' that are discussed. Foreign keys and
primary keys are important. What are these and how are they used in database design?
In a database design, Primary keys and foreign keys are essential concepts for
Primary keys must contain UNIQUE values, and cannot contain NULL values.
A table can have only ONE primary key; and in the table, this primary key can
consist of single or multiple columns (fields). It guarantees that every row in a table may
The FOREIGN KEY constraint is used to prevent actions that would destroy links
between tables.
A FOREIGN KEY is a field (or collection of fields) in one table, that refers to
The table with the foreign key is called the child table, and the table with the primary
key is called the referenced or parent table. In other words, primary keys uniquely pick
out statistics inside a table, and overseas keys establish relationships between tables by
linking to the Primary keys in different tables, selling records integrity and facilitating
6. From the Hospital Database what SQL code will pull the Doctors Last Name
FROM doctors;
7. From the Hospital Database what SQL code will pull just the Doctors Unique
ID?
SELECT doctor_id
FROM doctors;
8. Is the Doctor's Unique ID a Key in the Doctors Table? If so, what kind?
Yes, it is most likely to be and Primary key because Unique ID needs to be Unique
and non-repetitive.
9. The following code is a basic two table join format. You can use this format to
FROM table1
ON table1.column_name = table2.column_name;
Describe the steps that are occurring based on the lecture slide that deals with
SQL processor operations. What is happening in the processor first? What is happening
The SQL code provided initiates with the SQL processor identifying the involved
tables, denoted as table1 and table2. Subsequently, the processor executes a LEFT
JOIN operation, merging rows from table1 with matching rows from table2 based on the
table1 are included in the outcome, and if there are corresponding rows in table2, they
are incorporated as well, with NULL values filling in for unmatched columns. Finally, the
processor selects the specified columns (column_name(s)) from the resulting dataset.
This sequence mirrors the logical order of SQL processor operations, starting with the
identification of tables, followed by the JOIN operation, and concluding with the selection
1) FROM CLAUSE
3)SELECT CLAUSE
9. What SQL code would JOIN admissions table information with patient
information?
SELECT *
FROM admissions
INNER JOIN patients ON admissions.patient_id = patients.patient_id;
10. If you were to modify that SQL code to provide just patient last name and
diagnosis what code would provide only those two fields in the SQL viewer?
FROM admissions
birth date, what code would provide only those three fields?
FROM admissions
SELECT statement?
If Using (*) in the SELECT statement in both cases it would retrieve all columns
from both the "patient" and "admissions" tables. Consequently, the number of fields
14. For 11 and 12 (above), how many records are present when the JOIN is
implemented?
The number of records produced by the JOIN operation is dependent on the data
stored in your database. The size of the result set is determined by the matching rows
between the "admissions" and "patient" tables, as specified in the JOIN condition
(admissions.patient_id = patients.patient_id).
corresponding rows in the "admissions" table, and each admission record would be
matched with the respective patient details during the JOIN. The final count of records is
influenced by how many admission records align with patients in the "patient" table.
To determine the exact record count, you need to execute the SQL query on your
specific database. If you want to obtain a count without retrieving all the details, you can
use the COUNT() function in your SQL query, as illustrated in the provided examples.
FROM admissions
FROM admissions
products table. First, look at the schematic and explain how its related based on the
chapter readings. Second, what code would JOIN these two tables?
In the Northwind Database, the link between the "categories" table and the
"products" table is established through the utilization of the category_id column. This
adheres to a standard practice in relational databases, where a column in one table (in
this case, the category_id in the "products" table) references the primary key column in
another table (specifically, the primary key category_id in the "categories" table). This
follows: • Foreign Key Relationship: In the "products" table, the category_id column
serves as a foreign key, pointing to the primary key in the "categories" table.
Consequently, each entry for a product in the "products" table is associated with a
specific category as defined in the "categories" table. To merge these two tables, a
typical SQL query involving the JOIN operation, specifically an INNER JOIN based on
16. How would you view Category Name and the Supplier ID in the SQL viewer?
To display the Category Name and Supplier ID in the SQL Viewer, you can utilize
"supplier_id") from the "categories" table. Adjust the column names as needed to match