Found 4219 Articles for MySQLi

How to find all tables that contains columnA and columnB in MySQL?

AmitDiwan
Updated on 08-Jul-2020 09:16:49

110 Views

To find specific column names, use information_schema.columns Here, I am using Id in place of columnA and Name in place of columnB −mysql> select table_name as TableNameFromWebDatabase    -> from information_schema.columns    -> where column_name IN ('Id', 'Name')    -> group by table_name    -> having count(*) = 3;This will produce the following output. Following are the table with columns Id and Name −+--------------------------+ | TableNameFromWebDatabase | +--------------------------+ | student                  | | distinctdemo             | | secondtable              | | groupconcatenatedemo   ... Read More

Avoiding rewrite attributes with MySQL AUTO_INCREMENT

AmitDiwan
Updated on 05-Nov-2019 09:29:46

61 Views

You can avoid with the help of providing the value (NULL, 0, DEFAULT) with AUTO_INCREMENT. Let us first create a table −mysql> create table DemoTable1350    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1350 values(NULL, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1350 values(0, 'Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1350 values(DEFAULT, 'Chris'); Query OK, 1 row affected (0.10 sec)Display all records ... Read More

Updating a MySQL table row column by appending a value from user defined variable?

AmitDiwan
Updated on 05-Nov-2019 09:28:27

255 Views

Let us first create a table −mysql> create table DemoTable1349    -> (    -> ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ProductPrice int    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1349(ProductPrice) values(7644); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1349(ProductPrice) values(90843); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable1349(ProductPrice) values(9083); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1349(ProductPrice) values(10000); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement ... Read More

How to order and select query with conditions in MySQL?

AmitDiwan
Updated on 05-Nov-2019 09:25:38

177 Views

Following is the syntax −select * from yourTableName order by yourColumnName=0, yourColumnName;Let us first create a table −mysql> create table DemoTable1348    -> (    -> Amount int    -> ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1348 values(100); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1348 values(0); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1348 values(90); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1348 values(45); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1348 values(0); Query ... Read More

Update a column based on another MySQL table’s column

AmitDiwan
Updated on 05-Nov-2019 09:23:40

439 Views

For this, you can use the join concept. Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int,    -> Name varchar(10)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(100, 'Bob'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select * from DemoTable1;This will produce the following output −+------+------+ | Id | Name | +------+------+ | 100 | Bob | +------+------+ 1 row in set (0.00 ... Read More

How to mask user email addresses with a different domain in MySQL?

AmitDiwan
Updated on 05-Nov-2019 08:40:59

387 Views

Let us first create a table −mysql> create table DemoTable1345    -> (    -> UserEmailAddress text    -> ); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert command. We have inserted email address here −mysql> insert into DemoTable1345 values('Carol123@gmail.com'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1345 values('987Sam@gmail.com'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1345 values('David_Miller@gmail.com'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1345 values('Bob@gmail.com'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select * ... Read More

MySQL query to select rows where column value is only 0, group by another column?

AmitDiwan
Updated on 05-Nov-2019 07:47:33

235 Views

For this, use group by. Let us first create a table −mysql> create table DemoTable1344    -> (    -> `SequenceId` int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientId int,    -> isMarried tinyint(1)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1344(ClientId, isMarried) values(4567, 0); Query OK, 1 row affected (0.45 sec) mysql> insert into DemoTable1344(ClientId, isMarried) values(9876, 0); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1344(ClientId, isMarried) values(5432, 1); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1344(ClientId, isMarried) ... Read More

Insert all the values in a table with a single MySQL query separating records by comma

AmitDiwan
Updated on 05-Nov-2019 07:42:58

209 Views

Let us first create a table −mysql> create table if not exists DemoTable1343    -> (    -> `_ClientId` int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(40),    -> ClientProjectDeadline date    -> )ENGINE=MyISAM, AUTO_INCREMENT=1000; Query OK, 0 rows affected (0.21 sec)Insert some records in the table using insert command with a single query −mysql> insert into DemoTable1343(ClientName, ClientProjectDeadline) values('Chris', '2019-09-24'), ('Bob', '2015-12-09'),    -> ('Mike', '2017-01-20'), ('Carol', '2018-03-31'); Query OK, 4 rows affected (0.10 sec) Records: 4 Duplicates: 0 Warnings: 0Display all records from the table using select statement −mysql> select * from DemoTable1343;This will produce the ... Read More

How to add a column from a select query but the value from the new column will be the row count of the MySQL select query?

AmitDiwan
Updated on 05-Nov-2019 07:30:01

255 Views

For this, you can use MySQL row_number(). Let us first create a table −mysql> create table DemoTable1342    -> (    -> Score int    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1342 values(80); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1342 values(98); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1342 values(78); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1342 values(89); Query OK, 1 row affected (0.07 sec)Display all records from the table using select statement −mysql> select ... Read More

Fetch the substring after last dot in MySQL

AmitDiwan
Updated on 05-Nov-2019 07:23:14

1K+ Views

To fetch the substring after last dot, use substring_index(). Let us first create a table −mysql> create table DemoTable1341    -> (    -> Value varchar(60)    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1341 values('John.123.@gmail.com' ); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1341 values('Carol.Taylor.gmail') ; Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1341 values('C.MyFolder.Location') ; Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select * from DemoTable1341;This will produce the following ... Read More

Advertisements