- 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
141 Views
To append 000, use the concept of ZEROFILL. Let us first create a table −mysql> create table DemoTable1913 ( Code int(4) ZEROFILL AUTO_INCREMENT NOT NULL, PRIMARY KEY(Code) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1913 values(1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1913 values(2); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1913 values(3); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1913 values(4); Query OK, 1 row affected (0.00 sec)Display all records from the table ... Read More
145 Views
For this, use ORDER BY along with LIMIT. Let us first create a table wherein we have a column with User id, logged in time, and name −mysql> create table DemoTable1911 ( UserId int, UserLoggedInTime time, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1911 values(100, '7:32:00', 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1911 values(101, '5:00:00', 'David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1911 values(102, '6:10:20', 'Mike'); Query OK, 1 row affected (0.00 ... Read More
459 Views
For this, you can use CASE WHEN statement. Let us first create a table −mysql> create table DemoTable1910 ( FirstName varchar(20), Marks int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1910 values('Chris', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('David', 85); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('Chris', 55); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('Chris', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('David', ... Read More
161 Views
To return list of databases, the syntax is as follows −select schema_name as anyAliasName from information_schema.schemata;Here is the query to return list of databases in MySQL −mysql> select schema_name as DatabaseName from information_schema.schemata;This will produce the following output −+---------------------------+ | DatabaseName | +---------------------------+ | mysql | | information_schema | | performance_schema | | sys | | business | | sample | | hello | | test | | mybusiness | | databasesample | | schemasample | | universitydatabase | | education | | mydatabase | | database1 | | sampledatabase | | test3 | | javadatabase2 | | javasampledatabase | | rdb | | onetomanyrelationship | | webtracker | | web | | commandline | | hb_student_tracker | | bothinnodbandmyisam | | customertracker | | tracker | | demo | | customer_tracker_database | | login | | onlinebookstore | | customer-tracker | | web_tracker | | instant_app | | 1233 | +---------------------------+ 36 rows in set (0.00 sec)
379 Views
For this, you need to use SET command only once. Let us first create a table −mysql> create table DemoTable1909 ( Id int NOT NULL, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1909 values(101, 'John', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1909 values(102, 'John', 'Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1909 values(103, 'Adam', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1909 values(104, 'David', 'Miller'); Query ... Read More
661 Views
Let us first create a table −mysql> create table DemoTable1908 ( Code text ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1908 values('MySQL(1)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MongoDB 2 Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MySQL(3)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('SQL Server(10)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MySQL 8 Database'); Query OK, 1 row affected (0.00 sec)Display all records from ... Read More
118 Views
Let us first create a table −mysql> create table DemoTable1907 ( UserId int NOT NULL AUTO_INCREMENT, UserName varchar(20), UserAge int, UserCountryName varchar(20), PRIMARY KEY(UserId) )ENGINE=MyISAM, AUTO_INCREMENT=100; Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1907(UserName, UserAge, UserCountryName) values('Chris', 26, 'US'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1907(UserName, UserAge, UserCountryName) values('David', 38, 'UK'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1907(UserName, UserAge, UserCountryName) values('John', 28, 'AUS'); Query OK, 1 row affected (0.00 sec)Display all records from the ... Read More
409 Views
To change format of dates, use the DATE_FORMAT() function. Let us first create a table −mysql> create table DemoTable1906 ( DueTime datetime ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1906 values(now()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values(curdate()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values('2017-10-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values('2015-01-12'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values('2018-04-25'); Query OK, 1 row affected (0.00 ... Read More
271 Views
To fasten the process, you can use INDEX. Let us first create a table −mysql> create table DemoTable1905 ( FirstName varchar(20), LastName varchar(20) , INDEX F_L_Name(FirstName, LastName) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1905 values('John', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1905 values('John', 'Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1905 values('Adam', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1905 values('John', 'Doe'); Query OK, 1 row affected (0.00 sec) ... Read More
308 Views
To escape backslashes, use PreparedStatement while inserting records. Let us first create a table −mysql> create table DemoTable1904 ( ClientId int, ClientName varchar(20), ClientAge int ); Query OK, 0 rows affected (0.00 sec)The Java code is as follows −import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class EscapeBackslashesDemo { public static void main(String[] args) { Connection con = null; PreparedStatement ps = null; try { con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?" + "useSSL=false", "root", "123456"); String query = "insert into DemoTable1904(ClientId, ... Read More