Joins

Joins The SQL Joins clause is used to combine records from two or more tables in a database. A JOIN is a means of merging two tables based on common fields. INNER JOIN: returns rows when there is a match in both tables. LEFT JOIN: returns all rows from the left table, even if there are no matches in the right table. RIGHT JOIN: returns all rows from the right table, even if there are no matches in the left table. FULL JOIN: returns rows when there is a match in one of the tables. Note: FULL JOIN cannot be implemented directly in MySQL dialet. In this dialect, FULL JOIN is the UNION between RIGHT JOIN and LEFT JOIN. ...

September 30, 2023 · 2 min · 372 words · Kiprono Elijah

Queries with Queries with SQL

Single-Valued Subqueries A single-valued subquery is a query that 1) produces a result with a single column and a single row and 2) is ’nested’ in the WHERE clause of another query. Subqueries must be enclosed in parentheses. A single-valued queries: SELECT AVG(days_to_cutoff) FROM accounts; Sing-valued sub-query: SELECT * FROM accounts WHERE days_to_cutoff > (SELECT AVG(days_to_cutoff) FROM accounts) ORDER BY days_to_cutoff; Key Points: Single-valued queries can be used in comparisons Subqueries are enclosed in parentheses Multi-Valued Subqueries A multi-valued subquery is a query that 1) returns a single-column result with zero, one, or more rows and 2) is ’nested’ in the WHERE clause of another query. Multi-valued subqueries always follow the IN operator. ...

September 30, 2023 · 1 min · 134 words · Kiprono Elijah

Creating Database Objects

Creating Tables in SQL New tables are defined in a database by entering a CREATE TABLE statement. In its simplest form, the CREATE TABLE statement includes a new table name and one or more column definitions. Tables are removed using the DROP TABLE statement. SQL Syntax for Creating Tables: CREATE TABLE table_name ( column1 datatype constraints, column2 datatype constraints, ... ); table_name: The name of the table you want to create. column1, column2, etc.: The names of the columns in the table. datatype: The data type for each column (e.g., INT, VARCHAR, DATE, etc.). constraints: Optional constraints (discussed in the next section) Example: Creating a simple table with basic columns: ...

September 30, 2023 · 3 min · 602 words · Kiprono Elijah

Maintaining and Managing Database Objects in SQL

Before we learn how to update data in SQL tables, let’s create two tables we will use: customers and orders. customers table USE ds2; # select database show tables; CREATE TABLE customers ( id INT PRIMARY KEY, name VARCHAR(30) NOT NULL, age INT DEFAULT - 99, address VARCHAR(45), salary DECIMAL(18 , 2 ) DEFAULT 2000.00 ); orders table CREATE TABLE orders ( id INT NOT NULL, date datetime, customer_id INT REFERENCES customers (id), amount DOUBLE, PRIMARY KEY (id) ); Inserting Rows Updating Rows New rows may be inserted into a table one at a time using the SQL INSERT statement. A table name and column list are specified in the INTO clause, and a value list, enclosed in parentheses, is entered in the VALUES clause. ...

September 30, 2023 · 3 min · 599 words · Kiprono Elijah

How to Install Python Manually in Linux

This guide will discuss how to install Python manually on a Linux machine. For your convenience, we will also discuss how to uninstall Python installed in this way. Steps to Follow to Install Python Manually First of all, we need to update package repositories and install dependencies. Step 1: Update repositories On Debian-based distributions, execute (modify the commands according to the distro you are running): sudo apt update sudo apt install build-essential zlib1g-dev \ libncurses5-dev libgdbm-dev libnss3-dev \ libssl-dev libreadline-dev libffi-dev curl Step 2: Download the stable release of Python on its official website In this step, go to https://www.python.org/downloads/source/ and download XZ compressed source tarball (.tar.xz) file. This file contains all the source files we can build to get the Python we want (I am downloading Python 3.10.5, so I get, Python-3.10.5.tar.xz file). ...

November 28, 2022 · 2 min · 347 words · Kiprono Elijah

SSH Essentials

Connecting to a Remote Server through SSH SSH (Secured Shell) is a program for accessing and managing remote machines. It is intended to provide secure encrypted communications between two untrusted hosts over an insecure network. In this article, we will refer to the machine initiating the SSH connection as the local or client system and the device on the receiving end as the server or remote machine. Note that the installation commands may be different based on the system you are running. Nevertheless, it should be easy to tweak these commands on Linux and MacOS. ...

November 24, 2022 · 4 min · 771 words · Kiprono Elijah