Found 4378 Articles for MySQL

Find records with double quotes in a MySQL column?

AmitDiwan
Updated on 22-Aug-2019 08:03:19

677 Views

Use LIKE to find records with double quotes. Following is the syntax −select *from yourTableName where yourColumnName LIKE '%"%';Let us first create a table −mysql> create table DemoTable740 (Value varchar(100)); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable740 values("\""); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable740 values("\"John"); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable740 values("Sam"); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable740;This will produce the following output -+-------+ | ... Read More

Finding the sum of integers from multiple MySQL rows in same column?

AmitDiwan
Updated on 22-Aug-2019 08:01:43

161 Views

Let us first create a table −mysql> create table DemoTable739 (Price int); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable739 values(100); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable739 values(50); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable739 values(1200); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable739 values(500); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable739 values(800); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable739;This will ... Read More

How to retrieve a value with MySQL count() having maximum upvote value?

AmitDiwan
Updated on 22-Aug-2019 08:10:27

77 Views

Let’s say we have some columns in the table, one for image path and another for the upvotes. However, the first column is the auto increment Id as shown below −mysql> create table DemoTable(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ImagePath varchar(100), UpvoteValue int ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ImagePath, UpvoteValue) values('Image1.jpeg', 90); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(ImagePath, UpvoteValue) values('Image2.jpeg', 10); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(ImagePath, UpvoteValue) values('Image3.jpeg', 120); Query OK, 1 ... Read More

Using Regex find strings containing a-z, A-Z and 0-9 in MySQL

AmitDiwan
Updated on 22-Aug-2019 08:00:19

396 Views

To find strings containing a-z, A-Z and 0-9, use BINARY REGEXP along with AND operator.Let us first create a table −mysql> create table DemoTable738 (UserId varchar(100)); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command  −mysql> insert into DemoTable738 values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable738 values('sAm456'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable738 values('98Carol'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable738 values('67david'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable738 values('69MIKE'); Query OK, 1 row affected (0.18 ... Read More

How to create an empty VIEW in MySQL?

AmitDiwan
Updated on 22-Aug-2019 07:58:54

592 Views

To create an empty view in MySQL, following is the syntax −create or replace view yourViewName as select yourValue AS yourColumnName, yourValue AS yourColumnName2, . . N from dual where false;Let us implement the above syntax in order to create an empty view in MySQL −mysql> create or replace view empty_view as    select "John Smith" AS ClientName,    "US" AS ClientCountryName,    false AS isMarried    from dual    where false; Query OK, 0 rows affected (0.20 sec)Let us check the description of the view −mysql> desc empty_view;This will produce the following output -+-------------------+-------------+------+-----+---------+-------+ | Field       ... Read More

Implementing DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP in MySQL

AmitDiwan
Updated on 22-Aug-2019 07:56:30

3K+ Views

With the DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP, a column has the current timestamp for its default value and is automatically updated to the current timestamp.Let us see an example and create a table −mysql> create table DemoTable737 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100),    StudentAdmissiondate datetime ); Query OK, 0 rows affected (0.68 sec)Following is the query to for CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP in MySQL −mysql> alter table DemoTable737 modify column StudentAdmissiondate timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; Query OK, 0 rows affected (2.20 sec) Records: 0 Duplicates: 0 Warnings: 0Let ... Read More

How to update all the entries except a single value in a particular column using MySQL?

AmitDiwan
Updated on 22-Aug-2019 07:54:03

989 Views

To update all the entries while ignoring a single value, you need to use IF().Let us first create a table −mysql> create table DemoTable736 (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(100),    isMarried boolean ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable736(CustomerName, isMarried) values('Chris', 0); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable736(CustomerName, isMarried) values('Robert', 0); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable736(CustomerName, isMarried) values('David', 0); Query OK, 1 row affected (0.24 sec) mysql> insert into ... Read More

Match optional end of line after every record with REGEXP?

AmitDiwan
Updated on 22-Aug-2019 08:00:26

39 Views

Let us first create a table −mysql> create table DemoTable(EmployeeCode varchar(100)); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('EMPLOYEE:100 John Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('EMPLOYEE:16537 Chris Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('EMPLOYEE:100 David Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('EMPLOYEE:100 23432 David Miller'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql>; select *from DemoTable;This will produce the following output ... Read More

How to merge rows in MySQL?

AmitDiwan
Updated on 22-Aug-2019 07:49:01

4K+ Views

To merge rows in MySQL, use GROUP_CONCAT().Let us first create a table−mysql> create table DemoTable734 (    Id int,    Name varchar(100) ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command−mysql> insert into DemoTable734 values(101, 'John'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable734 values(102, 'John'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable734 values(103, 'Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable734 values(104, 'Chris'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable734 values(104, 'Chris'); Query OK, 1 row affected ... Read More

Search records on the basis of date in MySQL?

AmitDiwan
Updated on 22-Aug-2019 07:45:58

112 Views

Let us first create a table -mysql> create table DemoTable732 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PassengerId int, PassengerName varchar(100), PassengerAge int, PassengerTravelDatetime datetime ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command -mysql> insert into DemoTable732(PassengerId, PassengerName, PassengerAge, PassengerTravelDatetime) values(110, 'Chris', 25, '2019-07-23 12:45:56'); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable732(PassengerId, PassengerName, PassengerAge, PassengerTravelDatetime) values(120, 'Robert', 24, '2019-07-21 11:05:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable732(PassengerId, PassengerName, ... Read More

Advertisements