MySQL Filtering table data

MySQL Filtering table data :

In database, when you need to view data from table it’s rare required to view all data each time. So sql give us some
method of filtering data that not required.

There are three ways to filter any table :

  • selected columns and all rows
  • selected rows and all columns
  • selected columns and selected rows

selected columns and all rows :

In this way you will write query as selected column name as your need.

Syntax :


select <column_name1>, <column_name2>....<column_name_n> from <table_name>;

Example :


select fname, lname from employee;

selected rows and all columns :

Sql provide where clause to filter row from table.

Syntax :

 


select * from <table_name> where <condition>;

In above query, sql engine compares each records in the table with the condition given in the where clause. Data display
only those records that satisfy the given condition.

Example :

 


select * from employee where salary='20000';

Note : With above condition you can use all standard operators like logical, arithmetic etc.

selected columns and selected rows :

SQL provide facilities to select column as well as row.

Syntax :

 


select <column_name1>, <column_name2>....<column_name_n> from <table_name> where <condition>;

Example :

 


select fname, lname from employee where salary='20000';


		
Advertisements

Change column name in MySQL

How to change column name in MySQL ?

To change column name in MySQL you can use alter command.

Query Syntax :

alter table lable_name change OldColumn_name Newcolumn_name varchar(size);

Example :

alter table employee change uname name varchar(35);

In above query employee is a table, uname is a old column name and name is a new column name with size specified above.

What is MySQL

MySQL(also called “My Sequel”) is an open source Relational Database Management System (RDBMS) which uses Structured Query Language (SQL) written in c, c++.
Its first version 3.19 released on 23 may 1995 by MySQL AB(a Swedish company) but currently developed and support by Oracle Corporation. Latest released version are 5.6.19 on 30 May 2014.
MySQL query is very easy, relaible and user friendly used to manipulate data with database which have InnoDB engine.

You can use the included command line tools, or MySQL Workbench that create and manage MySQL databases, build database structures, back_up data, inspect status, and work with data records.