SQL Archive

Foreign Keys Made Simple with MySQL by examples

In plain English : A FOREIGN KEY in one table points to a PRIMARY KEY in another table. A foreign key places constraints on data in the related tables to ensure and guarantee data referential integrity as well as consistency. Foreign Key Syntax: create table abc( abc_id int not null ..... ... ...Read More

SQL SELECT Tutorial for Nested Queries ( Sub Queries )

A Subquery or Inner query or Nested query is a query within another SQL query and embedded within the WHERE clause. A subquery is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved. Subqueries can be used with ...Read More

SQL tutorial for using Having with Examples

The HAVING statment  is added to SQL because the WHERE keyword could not be used with aggregate functions ( such as count, max …) The syntax for using HAVING is as below:   SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value; Example for Database ...Read More

Advanced SQL SELECT Tutorial using Aggegrate Functions by Examples

The important SQL command is SELECT statement. The SQL SELECT statement is used to query or retrieve data from a table in the database. A query may retrieve information from specified columns or from all of the columns in the table: Syntax of SQL SELECT Statement: SELECT column_list FROM table-name [WHERE Clause] ...Read More

SQL Simple Exercises using MySQL and phpMyAdmin

1 Open phpMyAdmin. Click : Databases to create a new database with the name : ecommerce, Click Create 2 Click on the database ecommerce on the left side. 3 Download the database ecommerce.sql file. 4 Click Import and choose Browse to upload the following SQL file. Click GO once done. 5 Click ...Read More

Database Porgramming : Creating a simple phone book using Java & a database ( HSQLDB )

In one of the last tutorial, we have created a simple phonebook system using a text file and Java Programming. For more details, click here. In this tutorial, we will be creating the same project but with the integration of a simple database management system called ( HSQLDB ). The program will ...Read More

Join : SELECT Tutorial using multiple database tables

The JOIN is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables. Tables in a database are often related to each other with keys. 1) Let’s suppose we have two database tables for : contacts and countries CREATE ...Read More

SQL SELECT Tutorial : Searching & Querying the database

The most commonly used SQL command is SELECT statement. The SQL SELECT statement is used to query or retrieve data from a table in the database. A query may retrieve information from specified columns or from all of the columns in the table. To create a simple SQL SELECT Statement, you must ...Read More

SQL Tutorial : Creating a Table and Inserting data ( MySQL & HSQLDB )

In this tutorial, we will learn how to create a database table and insert data into it,   The example we will consider is a simple phone book to store names, last names, ages, email and phone numbers for people. What is SQL? SQL stands for Structured Query Language SQL lets you ...Read More

SQL Hello World: A simple guide to database systems using HSQLDB

In this tutorial, we will learn how to create a simple database and play with its content. The example we will consider is a simple phone book to store names, last names and phone numbers for people. 1) We need to download the DBMS  ( HSQLDB ): [a software that eases and ...Read More