0% found this document useful (0 votes)
29 views

SQL Statements For Beginners To Master

The document shows the SQL commands to create 3 tables (books, authors, books_authors) in a mybookstore database and populate them with sample data. It then shows some SELECT queries to retrieve data from the tables.

Uploaded by

Maryam Yusuf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

SQL Statements For Beginners To Master

The document shows the SQL commands to create 3 tables (books, authors, books_authors) in a mybookstore database and populate them with sample data. It then shows some SELECT queries to retrieve data from the tables.

Uploaded by

Maryam Yusuf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CREATE DATABASE mybookstore;

use mybookstore;
CREATE TABLE books (isbn INT NOT NULL, title VARCHAR (50) NOT NULL, price FLOAT
NOT NULL, qty INT NOT NULL)
;
CREATE TABLE books_authors (authorID INT NOT NULL, isbn INT NOT NULL)
;
CREATE TABLE authors (authorID INT NOT NULL, name VARCHAR (30) NOT NULL, email
VARCHAR (30) NOT NULL)
;

INSERT INTO books VALUES (1001, 'Java for Dummies',11.11,11) ;


INSERT INTO books VALUES (1002, 'Only Java',22.22,22);
INSERT INTO books VALUES (1003, 'Java ABC', 33.33, 33) ;
INSERT INTO books VALUES (1004, 'Java 123',44.44,44) ;
INSERT INTO authors VALUES(1, 'Tan Ah Teck', '[email protected]');
INSERT INTO authors VALUES (2, 'Mohamed Ali', '[email protected]');
INSERT INTO authors VALUES(3, 'Kumar', '[email protected]');
INSERT INTO authors VALUES (4, 'Kelvin Jones', '[email protected]');
INSERT INTO books_authors VALUES (1,1001) ;
INSERT INTO books_authors VALUES (1,1001) :
INSERT INTO books_authors VALUES(3, 1001) ;
INSERT INTO books_authors VALUES (1,1002) ;
INSERT INTO books _authors VALUES (3,1002) ;
INSERT INTO books authors VALUES (2,1003) :
INSERT INTO books_authors VALUES (2,1004) ;

SELECT * FROM books;


SELECT * FROM authors;
SELECT * FROM books_authors;

SELECT books.title, books.price, books.qty


FROM books
WHERE books.price<20:

SELECT authors.name, authors.email, books.title


FROM authors, books
WHERE books.title='Java for Dummies’;

SELECT authors.name, authors.email, books.title


FROM books, authors
WHERE title LIKE ‘Java%’;

Maryam Yusuf Suleiman


181213008

You might also like