
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4381 Articles for MySQL

277 Views
The ZF stands for ZEROFILL i.e. row declarations for zero fill Let us first create a table. Here, we have set the int field size to be 10 −mysql> create table DemoTable1332 -> ( -> Number int(10) ZEROFILL NOT NULL DEFAULT 0 -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1332 values(); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1332 values(1); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1332 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert ... Read More

455 Views
To use the @ sign, use MySQL SET command. The @sign is used to set user-defined variables. Following is the syntax −SET @anyVariableName:=yourValue;Let us first create a table −mysql> create table DemoTable1331 -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1331 values(10, 'Chris'); Query OK, 1 row affected (0.71 sec) mysql> insert into DemoTable1331 values(101, 'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1331 values(40, 'Bob'); Query OK, 1 row affected (0.12 sec) ... Read More

201 Views
You do not need to format a number in MySQL, for this use DECIMAL data type. Let us first create a table −mysql> create table DemoTable1330 -> ( -> Amount DECIMAL(10, 2) -> ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1330 values(10944.7893); Query OK, 1 row affected, 1 warning (0.13 sec) mysql> insert into DemoTable1330 values(9848.44); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1330 values(8009.90); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1330 values(1000.99); Query OK, 1 row affected ... Read More

295 Views
For this, you can use substring() along with length(). Let us first create a table −mysql> create table DemoTable1329 -> ( -> StudentName varchar(40) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1329 values('David Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1329 values('Chris Brown'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1329 values('Adam Smith'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1329 values('John Doe'); Query OK, 1 row affected (0.44 sec)Display all records from the ... Read More

929 Views
Fir this, use INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1 -> ( -> Id int, -> Name varchar(20), -> Age int -> ); Query OK, 0 rows affected (1.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(100, 'Chris', 24); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable1 values(101, 'Adam', 23); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1 values(102, 'John', 25); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1 values(103, 'Carol', 26); Query ... Read More

365 Views
For this, you can use time_format(). Let us first create a table −mysql> create table DemoTable1326 -> ( -> Arrivaltime time -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1326 values('12:10:45'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1326 values('20:00:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1326 values('22:45:55'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1326 values('04:10:24'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select * ... Read More

136 Views
To order MySQL results without identifier, the syntax is as follows −select * from yourTableName order by 1 DESC LIMIT yourLimitValue;Let us first create a table −mysql> create table DemoTable1325 -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1325 values(100, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1325 values(101, 'Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1325 values(120, 'David'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More

2K+ Views
You can use aggregate function count(*). If it returns a value greater than 1, that would mean the table has composite primary key.Let us first create a table −mysql> create table DemoTable1324 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentAge int, -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (0.52 sec)Here is the query to add composite primary key −mysql> alter table DemoTable1324 ADD CONSTRAINT constr_IdAgeCountry PRIMARY KEY (StudentId, StudentAge, StudentCountryName); Query OK, 0 rows affected (1.29 sec) Records: 0 Duplicates: 0 Warnings: 0Following is the query to identify composite ... Read More

268 Views
You can use the concept INFORMATION_SCHEMA.TABLES for this. Let us first create a table. This would be our most recent table −mysql> create table DemoTable1323 -> ( -> FirstName varchar(10) -> ); Query OK, 0 rows affected (0.43 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1323 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1323 values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1323 values('Bob'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable1323;This will produce ... Read More

145 Views
For this, use MySQL YEAR() as in the below syntax −select * from yourTableName where year(yourColumnName)=’yourYearValue’;Let us first create a table −mysql> create table DemoTable1322 -> ( -> DOB date -> ); Query OK, 0 rows affected (0.55 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable1322 values('1999-04-12'); Query OK, 1 row affected (0.68 sec) mysql> insert into DemoTable1322 values('2010-12-01'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1322 values('2015-03-09'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1322 values('2007-05-24'); Query OK, 1 row affected (0.08 sec)Display all records from the table ... Read More