MySQLi Articles

Page 320 of 341

Grant a user permission to only view a MySQL view?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 1K+ Views

To grant a user permission to only view a MySQL view, use the below syntaxGRANT SELECT ON yourDatabaseName.yourViewName TO ' yourUserName@'yourLocalHost';First you need to display all the view names from a table. The syntax is as follows −SHOW FULL TABLES IN yourDatabaseName WHERE TABLE_TYPE LIKE 'VIEW';Now implement the above syntax to display all views from a database. Here I am using the database name ‘test’. The query is as follows −mysql> SHOW FULL TABLES IN test WHERE TABLE_TYPE LIKE 'VIEW';The following is the output −+-------------------------------+------------+ | Tables_in_test                | Table_type | +-------------------------------+------------+ | empidandempname_view ...

Read More

Using "TYPE = InnoDB" in MySQL throws an exception?

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 485 Views

You can use ENGINE = InnoDB in place of TYPE = InnoDB, since the usage of TYPE became obsolete in MySQL version 5.1.The version we are using for our example is MySQL version 8.0.12. Let us check the MySQL version. The query is as follows −mysql> select version();The following is the output −+-----------+ | version() | +-----------+ | 8.0.12    | +-----------+ 1 row in set (0.00 sec)Here is the example of TYPE = InnoDB. Error is visible in MySQL 8 −mysql> create table Product_Information    -> (    -> ProductId int,    -> ProductName varchar(10),    -> ProductDeliveryDate datetime ...

Read More

MySQL CAST as DATE?

George John
George John
Updated on 30-Jul-2019 622 Views

There is no difference between cast as Date and date() function in MySQL.The syntax of both cast() and date() is as follows −cast(yourDateTimeColumnName as Date) date(yourDateTimeColumnName)Both functions internally call Item_date_typecast. To check both the functions, let us create a table. The query to create a table is as follows −mysql> create table CastAsDateDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> ArrivalTime datetime,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.71 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ...

Read More

How to update field to add value to existing value in MySQL?

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 8K+ Views

You can update field to add value to an existing value with the help of UPDATE and SET command. The syntax is as follows −UPDATE yourTableName SET yourColumnName = yourColumnName+integerValueToAdd WHERE yourCondition;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table addingValueToExisting    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(30),    -> GameScore int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.58 sec)Insert records in the table using insert command. The query is as follows −mysql> insert ...

Read More

Selecting a single row in MySQL?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 2K+ Views

If you want to select a single row on the basis of primary key, use the WHERE clause. The syntax is as follows −SELECT * FROM yourTableName WHERE yourPrimaryKeyColumnName = someValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table selectWithPrimaryKey    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> Marks int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. The query is ...

Read More

Is there a way in MySQL to reverse a boolean field with a single query?

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 1K+ Views

Yes, you can use if() function from MySQL to reverse a boolean field. The syntax is as follows −UPDATE yourTableName SET yourBooleanColumnName = IF(yourBooleanColumnName, 0, 1);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ReverseBooleanField    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> isValid BOOLEAN    -> ,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ReverseBooleanField(isValid) values(true); ...

Read More

Sum values of a single row in MySQL?

George John
George John
Updated on 30-Jul-2019 1K+ Views

You can use below syntax to sum values of a single row −Case 1 − The following is the syntax if your column does not have NULL value −SELECT yourColumnName1+yourColumnName2+yourColumnName3+.......+N as anyVariableName FROM yourTableName;Case 2 − If your column has NULL value then use this syntax −SELECT IFNULL(yourColumnName1, 0)+ IFNULL(yourColumnName2, 0)+ IFNULL(yourColumnName3, 0)+.............+N AS anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SumValueOfSingleRow    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> FirstValue int,    -> SecondValue int,    -> ThirdValue ...

Read More

How to quote values using MySQL group_concat?

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 1K+ Views

You can quote values using concat() and grop_concat() function from MySQL. The syntax is as follows −SELECT GROUP_CONCAT(CONCAT(' '' ', yourColumnName, ' '' ' )) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Group_ConcatDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,      -> Value int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into Group_ConcatDemo(Value) ...

Read More

MySQL Query a List of Values?

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 6K+ Views

To query a list of values, you can use IN operator. The syntax is as follows −SELECT * FROM yourTableName WHERE yourColumnName IN(Value1, Value2, ...N) ORDER BY FIELD(yourColumnName, Value1, Value2, ...N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ListOfValues    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(30),    -> Age int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert ...

Read More

How do I pass a variable to a MySQL script?

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 4K+ Views

You can pass a variable to a MySQL script using session variable. First you need to set a session variable using SET command. After that you need to pass that variable to a MySQL script.The syntax is as follows −First Step: Use of Set command.SET @anyVariableName − = ’yourValue’;Second Step: Pass a variable to a MySQL script.UPDATE yourTableName SET yourColumnName1 = yourColumnName1+integerValue WHERE yourColumnName2 = @anyVariableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Employee_Information    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT,    -> ...

Read More
Showing 3191–3200 of 3,404 articles
« Prev 1 318 319 320 321 322 341 Next »
Advertisements