- 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
592 Views
You can use DATE_ADD() function with where clause for this. Let us first create a table −mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.54 sec)Note : The current date and time is as follows, we found using NOW() −mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-04 20 :43 :57 | +-----------------------+ 1 row in set (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-16'); Query OK, 1 ... Read More
109 Views
Use BETWEEN clause to search between columns. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score1 int, Score2 int ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score1, Score2) values(45, 65); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(Score1, Score2) values(450, 680); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Score1, Score2) values(800, 900); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement ... Read More
502 Views
To concatenate two tables, UNION ALL in MySQL. Let us create a table −mysql> create table DemoTable1 ( Id int, FirstName varchar(20) ); Query OK, 0 rows affected (1.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10, 'John'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1 values(20, 'Carol'); Query OK, 1 row affected (0.28 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;Output+------+-----------+ | Id | FirstName | +------+-----------+ | 10 | John | ... Read More
76 Views
To view the indexes, you can use SHOW command.Following is the syntax −show index from yourTableName;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.46 sec)Following is the query to create an index −mysql> create index id_FirstName on DemoTable(Id, FirstName); Query OK, 0 rows affected (0.52 sec) Records : 0 Duplicates : 0 Warnings : 0Following is the query to view the indexes I have set up in MySQL −mysql> show index from DemoTable;This will produce ... Read More
1K+ Views
To work with multiple AND conditions in MySQL, following is the syntax −select *from yourTableName where yourColumnName1=yourValue1 and yourColumnName2=yourValue2 and yourColumnName3=yourValue3;Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAge int, StudentCountryName varchar(40) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName, StudentAge, StudentCountryName) values('John', 23, 'US'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName, StudentAge, StudentCountryName) values('Carol', 21, 'UK'); Query OK, 1 row affected (0.15 sec) mysql> insert ... Read More
311 Views
To check if table exists, use the following syntax −CREATE TABLE IF NOT EXISTS yourTableName ( yourColumnName1 dataType, . . . . N );Here, we will try to create a table that already exists and then it will produce a warning message “Table already exists”. Let us first create a table. This table already exists −mysql> CREATE TABLE IF NOT EXISTS DemoTable ( Id int ); Query OK, 0 rows affected, 1 warning (0.06 sec)The warning message is as follows −mysql> show warnings;Output+-------+------+-------------------------------------+ | Level | Code | Message ... Read More
727 Views
Let us first create a table −create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate timestamp );Insert some records in the table using insert command. Here, we have included the current date with NOW() −INSERT INTO DemoTable(ShippingDate) VALUES(now());Display all records from the table using select statement −SELECT *FROM DemoTable;OutputFollowing is the screenshot of query in MySQL workbench to set NOW() to timestamp field “ShippingDate”. The query also displays the output below −
289 Views
Yes, it is possible with triggers. You can create trigger for automatic conversion on lower case. Let us first create a table −mysql> create table DemoTable ( StudentSubject text ); Query OK, 0 rows affected (0.61 sec)Let us create a trigger for automatic conversion on lower case −mysql> CREATE TRIGGER lowerCaseOnInsertDemo BEFORE INSERT ON DemoTable FOR EACH ROW SET NEW.StudentSubject = LOWER(NEW.StudentSubject); Query OK, 0 rows affected (0.21 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MOngoDb'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('JaVA'); Query OK, ... Read More
110 Views
Use LIKE for this, as shown below −select *from yourTableName where yourColumnName LIKE 'A%';Let us first create a table −mysql> create table DemoTable ( StudentName varchar(100) ); Query OK, 0 rows affected (0.66 sec)Now you can insert some records in the table using insert command −mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Aaron Taylor'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.27 sec)Display ... Read More
276 Views
To display two decimals, use number_format(). Let us first write the PHP code for the same. We have first declared two variables are initialized −$number1=10.3423; $number2=10;Now, display the two decimals using the number_format() function −$result1=number_format ($number1, 2); $result2=number_format ($number2, 2);ExampleFollowing is the example −OutputFollowing is the snapshot of PHP code −10.34 10.00