You are on page 1of 8

Statement

SELECT ALL IN THE TABLE

SELECT * FROM contactstable.soundin

SELECT A PARTICULAR COLUMN

SELECT GAUGE FROM contactstable.s

version number and the current date


use mysql as a simple calculator
select user

SELECT VERSION(), CURRENT_DATE;


SELECT SIN(PI()/4), (4+1)*5;
SELECT USER();
USE TABELS:
SHOW DATABASES;
show tables;

SHOW DATABASES;
CREATE DATABASE menagerie;
USE menagerie
SHOW TABLES;

CREATE TABLE pet (name VARCHAR(2


DESCRIBE pet;

Here you can upload txt file data to d


create a text file pet.txt

LOAD DATA LOCAL INFILE '/path/pet.tx

INSERT INTO pet VALUES ('Puffball','D


SELECT what_to_select
FROM which_table
WHERE conditions_to_satisfy;
Selecting All Data

SELECT * FROM pet;


UPDATE pet SET birth = '1989-08-31'

Selecting Particular Rows

SELECT * FROM pet WHERE name = 'B

SELECT * FROM pet WHERE birth >= '

SELECT * FROM pet WHERE species =

SELECT * FROM pet WHERE species =

SELECT * FROM pet WHERE (species =


Selecting Particular Columns

SELECT name, birth FROM pet;

SELECT owner FROM pet;


SELECT DISTINCT owner FROM pet;

SELECT name, species, birth FROM pe


Sorting Rows-ascending

SELECT name, birth FROM pet ORDER

descending

SELECT name, birth FROM pet ORDER

ascending and descending

SELECT name, species, birth FROM pe

Date Calculations

Que

OM contactstable.sounding;

GE FROM contactstable.sounding;

SION(), CURRENT_DATE;

PI()/4), (4+1)*5;

R();

BASES;

Table example

BASES;

ABASE menagerie;

erie

ES;

LE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DAT

et;

n upload txt file data to database

t file pet.txt

LOCAL INFILE '/path/pet.txt' INTO TABLE pet;

O pet VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);

t_to_select
_table
ditions_to_satisfy;

OM pet;
SET birth = '1989-08-31' WHERE name = 'Bowser';

OM pet WHERE name = 'Bowser';

OM pet WHERE birth >= '1998-1-1';

OM pet WHERE species = 'dog' AND sex = 'f';

OM pet WHERE species = 'snake' OR species = 'bird';

OM pet WHERE (species = 'cat' AND sex = 'm') OR (species = 'dog' AND sex = 'f');

e, birth FROM pet;

er FROM pet;

TINCT owner FROM pet;

e, species, birth FROM pet WHERE species = 'dog' OR species = 'cat';

e, birth FROM pet ORDER BY birth;

e, birth FROM pet ORDER BY birth DESC;

e, species, birth FROM pet ORDER BY species, birth DESC;

Query

Table examples starts here

, sex CHAR(1), birth DATE, death DATE);

sex = 'f');

You might also like