You are on page 1of 2

DBMS Lab Notes

Create a database

create DATABASE Tablename;

Create a table

CREATE TABLE Employee(

employee_id int(4),

first_name varchar(16),

last_name varchar(10)

);

Insert values into a table

INSERT INTO noob(employee_id, first_name, last_name)

VALUES

(1,'Adolf','Hitler'),

(2,'George','Bush');

Querying information

Show how much each employee makes yearly as

with only their last names.

SELECT concat(last_name, " makes ", salary*12, " yearly.") AS "employee" FROM
employees;

Sorting

SELECT last_name

FROM employees

ORDER BY last_name ASC|DESC;

LIKE

SELECT * FROM employees

WHERE Job_Id LIKE '%SA\_%';

NULL

SELECT * FROM employees

WHERE Job_Id IS NULL;

OPERATORS

AND, OR, NOT, BETWEEN, >, <, <>

<> = not equal to

Joining tables

equijoins

select E.employee_id, E.last_name, E.department_id, D.department_id,


D.location_id

FROM employees as E, departments as D

WHERE E.department_id = D.department_id;

Join clause

select E.employee_id, E.last_name, E.department_id, D.department_id,


D.location_id

FROM employees as E JOIN departments as D

ON (E.department_id = D.department_id);

You might also like