Insert Into Select Into a Table with Auto Increment in MySQL

AmitDiwan
Updated on 30-Dec-2019 07:17:37

1K+ Views

Let us create a table −mysql> create table DemoTable1923    (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1923(UserId, UserName)      select 101 as UserId, 'Chris' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1  Duplicates: 0  Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName)     select 102 as UserId, 'Robert' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1  Duplicates: 0  Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName) ... Read More

Delete Records from MySQL Table Using IN in a Single Query

AmitDiwan
Updated on 30-Dec-2019 07:16:08

230 Views

Let us create a table −mysql> create table DemoTable1922    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1922(StudentName) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Robert'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Mike'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1922;This ... Read More

Fix a Specific Column Value and Display Random Values for Other Rows in MySQL

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

175 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 into DemoTable1921 values(40); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(80); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(820); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(10); Query OK, 1 row affected (0.00 sec)Display all records from the ... Read More

Group Marks of a Student and Display Total in Column

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 DemoTable1920 values('Chris', 67); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('David', 97); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('Chris', 57); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('David', 45); Query OK, 1 row affected (0.00 sec) mysql> ... Read More

Using DECLARE to Create Variables in MySQL

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

559 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 Output;    end ;    // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;Now you can call a stored procedure using call command −mysql> call square_demo(15);This will produce the following output −+-----------------------+ | Output                | +-----------------------+ | Your Square Value=225 | +-----------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)

jQuery Traversing and Filtering

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

236 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(){       $("button").click(function(){          $("h2").not(".demo").css("color", "orange");       });    }); h2 { color: blue; } Student Info This is a demo text. Exam Info This is a demo text. Teacher's Info This is a demo text. Click me OutputThis ... Read More

Fix Error 1396 (HY000): Operation Create User Failed in MySQL

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. The new user created above is visible in the below list of all users along with host −+------------------+-----------+ | user             |      host | +------------------+-----------+ | Bob              |         % | | Charlie   ... Read More

usleep Function in PHP

George John
Updated on 30-Dec-2019 07:01:37

94 Views

The usleep() function delays execution of the current script for few microseconds.Syntaxusleep(msec)Parametersmsec − The number of microseconds to delay the script.ReturnThe usleep() function returns nothing.Example Live DemoOutputThe following is the output.03:06:08 03:06:10 03:06:15

Unpack Function in PHP

Chandu yadav
Updated on 30-Dec-2019 07:00:49

464 Views

The unpack() function unpacks data from a binary string.Syntaxunpack(format, data)Parametersformat − The format to use. Here are the possible valuesa −NUL-padded stringA − SPACE-padded stringh − Hex string, low nibble firstH − Hex string, high nibble firstc − signed charC −unsigned chars − signed short (always 16 bit, machine byte order)S − unsigned short (always 16 bit, machine byte order)n − unsigned short (always 16 bit, big endian byte order)v − unsigned short (always 16 bit, little endian byte order)i − signed integer (machine dependent size and byte order)I − unsigned integer (machine dependent size and byte order)l − signed ... Read More

uniqid Function in PHP

Arjun Thakur
Updated on 30-Dec-2019 06:59:26

336 Views

The uniqid() function generates a unique ID based on the current time in microseconds.Syntaxuniqid(prefix, more_entropy)Parametersprefix − The prefix to the unique ID.more_entropy − The more entropy at the end of the return value.ReturnThe uniqid() function returns unique identifiers as string.Example Live DemoOutputThe following is the output.5bfd5bd045faa

Advertisements