Categories
MySQL

Filter Rows Using WHERE Statement

In SELECT statement you can filter with condition to get actual result. Using WHERE clause you will get the data from the table that you exactly need. Here is sample sql for Filter Rows: SELECT name, address FROM users WHERE state = ‘AL’;

Categories
MySQL

MySQL UNION Operator

Using MySQL UNION Operator you can combine two or more result set from a multiple table into a single result set. UNION operator eliminates duplicate rows from the result set even you forgot to use DISTINCT operator. UNION ALL allows duplicate rows remain in the result. In the corresponding SELECT statements the number of columns […]

Categories
MySQL

MySQL INDEX

For improving the speed of operation in a table we use MySQL INDEX. We can create more than one field as a index field in a table. This is basically use for searching process so that it can lookup records very fast. As it fetches record very fast from the database, during insert and update […]

Categories
MySQL

Database Manage in MySQL

Database Manage in MySQL is a first priority to maintain a database. Here you will learn how you can manage database i.e. create a new database in MySQL, remove existing database etc. A database is nothing but a container of data that stores any kind of data. Here is how database manage: Creating DatabaseCREATE DATABASE […]

Categories
MySQL

Compare two tables in MySQL

When migrate data you need to compare two tables and identify the unmatched results records. Suppose you have two tables table1 and table2 with same columns and values. If any one table has any extra row then using below query you can get the unmatched results. Compare two tables: SELECT id, name FROM ( SELECT […]

Categories
MySQL

Manage Triggers in MySQL

Here you will learn how to manage triggers like modifying, removing etc. To display the trigger use following sql: SELECT * FROM Information_Schema.Triggers WHERE Trigger_schema = ‘database_name’ AND Trigger_name = ‘trigger_name’; To view trigger: SHOW TRIGGERS; To drop a trigger: DROP TRIGGER tbl_name.trigger_name

Categories
MySQL

MySQL ORDER BY Clause

Using MySQL ORDER BY Clause you can sort table columns by ascending or descending. Suppose we have a table ‘tbl’ with column ‘name’ and a row like below values: 1 1B 10 2 10C 2A 10Z So, when you sort by name: SELECT name FROM tbl ORDER BY name; So, when you sort by that […]

Categories
MySQL

MySQL Event

In MySQL you can add an event to a database that runs in a interval to automate database tasks. You can wait for intervals and check the table to see the changes. By default, the event scheduler thread is not enabled in the database. You need to enable this: SET GLOBAL event_scheduler = ON; Or […]

Categories
MySQL

Store IP Addresses as UNSIGNED INT

Want to store IP addresses in database and still using VARCHAR(15)? You can actually store IP addresses as integer values because using INT you go down to 4 bytes of space and have a fixed size field. As the range of a IP Addresses are 32 bit unsigned integer you can use your column as […]

Categories
MySQL

MySQL export table to CSV

MySQL provides an easy way to export table result set into a CSV file. Suppose we have a query like: SELECT name, email, age FROM users WHERE status = ‘Active’; So if we need to export this data into a csv file then using below query we can do: SELECT name, email, age FROM users […]