Found 4219 Articles for MySQLi

UPDATE with logical AND operator in MySQL

AmitDiwan
Updated on 28-Feb-2020 05:34:58

326 Views

For this, you can use AND operator with WHERE clause. Let us first create a table −mysql> create table DemoTable1616     -> (     -> StudentId int,     -> StudentName varchar(20),     -> StudentMarks int     -> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1616 values(101, 'Chris', 56); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1616 values(102, 'Bob', 87); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1616 values(103, 'David', 56); Query OK, 1 row affected (0.20 sec) ... Read More

MySQL query to get a single value from position of comma-separated string?

AmitDiwan
Updated on 17-Dec-2019 06:19:15

434 Views

For this, use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable1615    -> (    -> ListOfSubject text    -> ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1615 values('Python, Java, MySQL, MongoDB, C, C++, ASP.net'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select * from DemoTable1615; This will produce the following output −+-----------------------------------------+ | ListOfSubject                           | +-----------------------------------------+ | Python, Java, MySQL, MongoDB, C, ... Read More

Get three records having higher value from MySQL

AmitDiwan
Updated on 17-Dec-2019 06:15:23

66 Views

Let us first create a table −mysql> create table DemoTable1614    -> (    -> StudentName varchar(20),    -> StudentScore int    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1614 values('Adam', 65); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1614 values('Chris', 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1614 values('Bob', 58); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1614 values('Sam', 98); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1614 values('Mike', 87); Query OK, 1 ... Read More

Is there a function similar to Oracle's trunc (sysdate) in MySQL?

AmitDiwan
Updated on 17-Dec-2019 06:13:01

697 Views

Yes, you can use DATE() to get only date part in MySQL and you can use CURDATE() to get the current date in MySQL.The current date is as follows −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-10-20 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable1613    -> (    -> PostingDate datetime    -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1613 values('2019-10-20 12:02:45'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1613 values('2018-10-20 12:02:45'); ... Read More

Delete a specific record from a MySQL table by using AND in WHERE clause

AmitDiwan
Updated on 26-Feb-2020 07:08:22

112 Views

MySQL AND is used in WHERE to fetch a record by filtering using multiple conditions. Let us first create a table−mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(103, 'Bob'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement ... Read More

Get the size of selected rows in MySQL

AmitDiwan
Updated on 17-Dec-2019 06:09:47

1K+ Views

To get the size of selected rows, use CHAR_LENGTH(). Let us first create a table −mysql> create table DemoTable1612    -> (    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1612 values('David', 'Brown'); Query OK, 1 row affected (0.75 sec) mysql> insert into DemoTable1612 values('John', 'Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1612 values('Bob', 'Taylor'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable1612;This ... Read More

Combine multiple text records to one in MySQL

AmitDiwan
Updated on 17-Dec-2019 06:04:48

188 Views

To combine multiple text records, use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable1611    -> (    -> Value text    -> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1611 values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1611 values('is'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1611 values('learning'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1611 values('Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1611 values('with'); Query OK, 1 row affected ... Read More

MySQL Order by a specific column x and display remaining values in ascending order

AmitDiwan
Updated on 26-Feb-2020 07:19:59

99 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> MonthNumber int    -> ); Query OK, 0 rows affected (1.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(6); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(8); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(5); ... Read More

Custom sorting using two different columns in MySQL?

AmitDiwan
Updated on 17-Dec-2019 06:01:17

147 Views

For this, use ORDER BY clause along with CASE statement. Let us first create a table −mysql> create table DemoTable1610    -> (    -> Marks int,    -> Name varchar(20)    -> ) ; Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1610 values(85, 'John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1610 values(78, 'Carol'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1610 values(78, 'John'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1610 values(85, 'Carol'); Query OK, 1 row affected ... Read More

Find specific records from a column with comma separated values in MySQL

AmitDiwan
Updated on 28-Feb-2020 07:28:16

718 Views

For this, you can use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable    -> (    -> ListOfValue varchar(20)    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('78, 89, 65'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('88, 96, 97'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('95, 96, 99, 100'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('78, 45, 67, 98'); Query OK, 1 row affected (0.10 sec)Display all ... Read More

Advertisements