- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 4378 Articles for MySQL
629 Views
Yes, an alternative is CONCAT_WS(). Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100) ); Query OK, 0 rows affected (0.74 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName) values('Bob'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | ... Read More
300 Views
For this, use REPLACE() function and replace empty space with the character. Let us first create a table −mysql> create table DemoTable (Subject text); Query OK, 0 rows affected (0.86 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Java in depth'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Data Structure and Algorithm'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------------------------+ | Subject | +------------------------------+ | Introduction ... Read More
336 Views
Use index to select top n rows efficiently. Let us first create a table −mysql> create table DemoTable (StudentName varchar(100), StudentScore int ); Query OK, 0 rows affected (0.66 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('John', 34); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Carol', 55); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Bob', 58); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Sam', 38); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Mike', 48); Query OK, 1 row ... Read More
68 Views
For this, you can use CHAR_LENGTH(). Use RAND() for random records. Let us first create a table −mysql> create table DemoTable (Subject text); Query OK, 0 rows affected (0.61 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('C'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('MySQL'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('MongoDB'); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values('RubyOnRails'); Query OK, 1 row affected (0.25 sec) mysql> insert ... Read More
398 Views
For this, you can use LAST_INSERT_ID(). Let us first create a table −mysql> create table DemoTable ( UserId int(6) unsigned zerofill NOT NULL AUTO_INCREMENT, UserAutoIncrement char(100) default null, PRIMARY KEY(UserId) ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+--------+-------------------+ | UserId | UserAutoIncrement | +--------+-------------------+ | 000001 | NULL | +--------+-------------------+ ... Read More
231 Views
To round seconds to nearest half minute, use CEILING(). Let us first create a table −mysql> create table DemoTable (secondValue int); Query OK, 0 rows affected (0.64 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values(27); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(118); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+-------------+ | secondValue | +-------------+ | 27 | | 56 ... Read More
1K+ Views
For this, you can use COUNT() function. Let us first create a table −mysql> create table DemoTable -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(100) -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName) values('John'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(EmployeeName) values('Carol'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(EmployeeName) values('David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(EmployeeName) values('Carol'); Query OK, 1 row affected ... Read More
764 Views
For this, use COALESCE() function from MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 200); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(NULL, 90); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(NULL, NULL); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(600, NULL); Query OK, 1 row affected (0.12 sec)Display all records from ... Read More
296 Views
Let us first create a table −mysql> create table DemoTable -> ( -> Amount int -> ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(500); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+--------+ | Amount | +--------+ | 100 | | 200 ... Read More
275 Views
For this, use CASE statement. Let us first create a table −mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('My name is John and this is my first tutorial on MySQL'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('This is Carol and I work on MongoDB'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+--------------------------------------------------------+ | Title ... Read More