AmitDiwan has Published 10744 Articles

Fix a specific column value and display random values for rest of the rows in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:14:43

169 Views

For random rows, you can use RAND(), whereas to fix a specific column, use ORDER BY clause. Let us create a table −mysql> create table DemoTable1921    (    Number int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Group the marks of a particular student from a table and display total marks in a separate column for each student?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:11:27

10K+ Views

To group marks, use MySQL GROUP BY. To sum, use MySQL sum()function. Let us first create a table −mysql> create table DemoTable1920    (    StudentName varchar(20),    StudentMarks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Using DECLARE to create variable in MySQL?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:09:30

554 Views

You can use DECLARE in a stored procedure. The syntax is as follows −declare yourVariableName yourDataType;To understand the above syntax, let us create a stored procedure:mysql> delimiter // mysql> create procedure square_demo(in Value int)    begin    declare magicValue int;    set magicValue=Value;    select concat('Your Square Value=', magicValue*magicValue) as ... Read More

jQuery Traversing Filtering

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:08:44

228 Views

Filtering methods in jQuery include eq(), filter(), not(), etc. Let us see some of them here−not() methodThe not() method in jQuery is used to return elements that do not match specific criteria.ExampleLet us see an example to implement the jQuery not() method− Live Demo    $(document).ready(function(){   ... Read More

Fix: ERROR 1396 (HY000): Operation CREATE USER failed in MySQL?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:03:08

3K+ Views

To fix the error, let us see how to create a user correctly. Let us create a user −mysql> create user 'Emma'@'localhost' IDENTIFIED BY 'emma_654'; Query OK, 0 rows affected (0.00 sec)Let us display all users along with host −mysql> select user, host from MySQL.user;This will produce the following output. ... Read More

Query the database for the values not in the MySQL table?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:57:24

122 Views

For this, you can use UNION ALL along with WHERE NOT EXISTS and implement NOT IN to ignore the values already in the table. Use SELECT with UNION ALL to add values not already in the table.Let us first create a table −mysql> create table DemoTable1918    (    Value ... Read More

How to parse a CSV file using PHP

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:56:12

564 Views

To parse a CSV file in PHP, the code is as follows. Under fopen(), set the path of the .csv file−Example$row_count = 1; if (($infile = fopen("path to .csv file", "r")) !== FALSE) {    while (($data_in_csv = fgetcsv($infile, 800, ", ")) !== FALSE) {       $data_count = ... Read More

Get all rows apart from first and last in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:55:04

185 Views

To get all rows apart from first and last, use subquery along with MIN() and MAX(). Let us first create a table −mysql> create table DemoTable1917    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentCode int,    StudentMarks int    ); Query OK, 0 rows affected (0.00 ... Read More

Performance of FOR vs FOREACH in PHP

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:53:00

2K+ Views

The 'foreach' is slow in comparison to the 'for' loop. The foreach copies the array over which the iteration needs to be performed.For improved performance, the concept of references needs to be used. In addition to this, ‘foreach’ is easy to use.ExampleBelow is a simple code example − Live DemoOutputThis will ... Read More

Write MySQL case statement to set custom messages for student’s result

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:51:31

184 Views

For this, set conditions using MySQL CASE statement −mysql> create table DemoTable1916    (    StudentName varchar(20),    StudentMarks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1916 values('Chris', 59); Query OK, 1 row affected (0.00 sec) ... Read More

Advertisements