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

mysql 1 (1)

Uploaded by

khushbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

mysql 1 (1)

Uploaded by

khushbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

mysql> SHOW DATABASES;

mysql> USE test

Database changed

Creating and Selecting a Database

mysql> CREATE DATABASE student;

mysql> USE student;

Creating a Table

Creating the database is the easy part, but at this point it is empty, as SHOW TABLES tells you:

mysql> SHOW TABLES;

mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),

species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

mysql> SHOW TABLES;

mysql> DESCRIBE pet;

mysql> INSERT INTO pet

VALUES ('pitbull','gullyboy','hamster','m','1999-03-30',NULL);

mysql> INSERT INTO pet

VALUES ('jeniffer','lopez',newyork','f','1999-03-3',NULL);

mysql> SELECT * FROM pet;

mysql> SELECT * FROM pet WHERE name = 'pitbull';

mysql>SELECT * FROM pet;


mysql>UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';
Selecting Particular Columns
You can select only particular rows from your table. For example, if you want to
verify the change that you made to Bowser's birth date, select Bowser's record
like this:
mysql>SELECT * FROM pet WHERE name = 'Bowser';
mysql>SELECT * FROM pet WHERE birth >= '1998-1-1';

You can combine conditions, for example, to locate female dogs:

mysql>SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';

mysql>SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';

mysql>SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm')


OR (species = 'dog' AND sex = 'f');

mysql>SELECT name, birth FROM pet;


mysql>SELECT owner FROM pet;
DISTINCT:
mysql>SELECT DISTINCT owner FROM pet;
You can use a WHERE clause to combine row selection with column selection. For
example, to get birth dates for dogs and cats only, use this query:
mysql>SELECT name, species, birth FROM pet
WHERE species = 'dog' OR species = 'cat';

mysql>SELECT name, birth FROM pet ORDER BY birth;


mysql>SELECT name, birth FROM pet ORDER BY birth DESC;

You might also like