Grant SELECT on All Tables in All Databases with MySQL

AmitDiwan
Updated on 24-Dec-2019 06:19:03

1K+ Views

For this, you can use GRANT SELECT statement as in the below syntax −GRANT SELECT ON *.* TO 'yourUserName'@'yourHostName';First list all the user names along with host −mysql> select user, host from mysql.user;This will produce the following output −+------------------+-----------+ | user             |      host | +------------------+-----------+ | Bob              |         % | | Charlie          |         % | | Robert           |         % | | User2       ... Read More

C Program for Naive Algorithm for Pattern Searching

sudhir sharma
Updated on 24-Dec-2019 06:18:02

8K+ Views

Pattern matching in C− We have to find if a string is present in another string, as an example, the string "algorithm” is present within the string "naive algorithm". If it is found, then its location (i.e. position it is present at) is displayed. We tend to create a function that receives 2 character arrays and returns the position if matching happens otherwise returns -1.Input: txt = "HERE IS A NICE CAP"    pattern = "NICE" Output: Pattern found at index 10 Input: txt = "XYZXACAADXYZXYZX"    pattern = "XYZX" Output: Pattern found at index 0    Pattern found at ... Read More

Select and Display Values from Two Different MySQL Columns

AmitDiwan
Updated on 24-Dec-2019 06:15:52

2K+ Views

For this, use UNION ALL. Let us first create a table −mysql> create table DemoTable1813      (      Name1 varchar(20),      Name2 varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1813 values('John', 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1813 values('Adam', 'Robert'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1813 values('Mike', 'Sam'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1813;This will produce the following ... Read More

Extract Column Name and Type from MySQL

AmitDiwan
Updated on 24-Dec-2019 06:14:15

506 Views

To extract column name and type, use INFORMATION_SCHEMA.COLUMNS −select concat(column_name, '=', data_type) as anyAliasName from information_schema.columns where table_schema= yourDatabaseName and table_name= yourTableName;Let us first create a table −mysql> create table DemoTable1812      (      Id int,      FirstName varchar(20),      Age int,      isMarried boolean,      status ENUM('ACTIVE', 'INACTIVE')      ); Query OK, 0 rows affected (0.00 sec)Here is the query to extract column name and type from MySQL:mysql> select concat(column_name, '=', data_type) as COLUMNNAMEANDTYPE from information_schema.columns      where table_schema= 'web' and table_name= 'DemoTable1812';This will produce the following output −+-------------------+ | COLUMNNAMEANDTYPE ... Read More

Add Unique Constraint to Alter Table in MySQL

AmitDiwan
Updated on 24-Dec-2019 06:13:14

434 Views

Let us first create a table −mysql> create table DemoTable1811      (      FirstName varchar(20),      LastName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Here is the query to add indexmysql> alter table DemoTable1811 ADD UNIQUE unique_index_first_last_name(FirstName, LastName); Query OK, 0 rows affected (0.00 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1811 values('John', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1811 values('John', 'Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1811 values('Adam', 'Smith'); Query OK, 1 ... Read More

Minimum Number of Jumps to Reach the End in C

sudhir sharma
Updated on 24-Dec-2019 06:12:27

673 Views

We are given, an array of non-negative integers denoting the maximum number of steps that can be made forward from that element. The pointer is initially positioned at the first index [0 index] of the array. Your goal is to reach the last index of the array in the minimum number of steps. If it is not possible to reach the end of the array then print the maximum integer.naive approach is to begin from initial{the primary} component and recursively call for all the components accessible from the first element. The minimum range of jumps to reach the end from ... Read More

Make FROM as Column Name in MySQL

AmitDiwan
Updated on 24-Dec-2019 06:11:46

592 Views

Use the backticks symbol to consider ‘from’ as column name since it is a reserved word. We will now create a table with from reserved word surrounded by backtick −mysql> create table DemoTable1810      (      `from` varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1810 values('US'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1810 values('UK'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1810 values('AUS'); Query OK, 1 row affected (0.00 sec)Display all records from the table using ... Read More

Fetch a Specific Column Value in MySQL

AmitDiwan
Updated on 24-Dec-2019 06:10:32

881 Views

To fetch a specific column value, use LIKE clause. Let us first create a table −mysql> create table DemoTable1809      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1809 values('John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1809 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1809 values('Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1809 values('Johnson'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement ... Read More

Display All Column Values in a Single Row Separated by Comma in MySQL

AmitDiwan
Updated on 24-Dec-2019 06:08:19

1K+ Views

For this, use GROUP_CONCAT() and CONCAT(). Let us first create a table −mysql> create table DemoTable1807      (      Id int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1807 values(101); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1807 values(102); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1807 values(103); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1807;This will produce the following output −+------+ | Id   | ... Read More

Select Rows in MySQL That Are 1 Day From Current Date

AmitDiwan
Updated on 24-Dec-2019 06:07:05

887 Views

To get data greater than equal to 1 day from the current date, use the concept of INTERVAL in MySQL.The current date is as follows −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-11-29 | +------------+ 1 row in set (0.00 sec)We will first create a table −mysql> create table DemoTable1806      (      DueDate datetime      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1806 values('2019-11-28'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1806 values('2019-11-29'); Query OK, 1 row affected (0.00 ... Read More

Advertisements