AmitDiwan has Published 10744 Articles

Perform multiple inserts with INSERT INTO SELECT and UNION in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:51:53

3K+ Views

To perform multiple inserts, the syntax is as follows −insert into yourTableName(yourColumnName1, yourColumnName2, yourColumnName3, ..N)    select yourValue1 as yourColumnName1, yourValue2 as yourColumnName2, yourValue3 as yourColumnName3, ......N    union    select yourValue1 as yourColumnName1, yourValue2 as yourColumnName2, yourValue3 as yourColumnName3, ......N . . NTo understand the above syntax, let us ... Read More

MySQL query to display records from a table filtered using LIKE with multiple words?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:49:12

319 Views

For this, use RLIKE and filter records as in the below syntax &Minus;select * from yourTableName    where yourColumnName rlike 'yourValue1|yourValue2';Let us first create a table −mysql> create table DemoTable1935    (    Subject varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using ... Read More

jQuery hasClass() with Examples

AmitDiwan

AmitDiwan

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

262 Views

The hasClass() method in jQuery is used to check if any of the selected elements is having a specified class name.SyntaxThe syntax is as follows −$(selector).hasClass(classname)Above, the parameter class name is the class name to search for in the selected elements.ExampleLet us now see an example to implement the jQuery ... Read More

MySQL query to select average from distinct column of table?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:46:21

537 Views

For getting average, use AVG() and use it with DISTINCT to calculate from distinct records. Let us first create a table −mysql> create table DemoTable1934    (    StudentName varchar(20),    StudentMarks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command ... Read More

jQuery has() with Examples

AmitDiwan

AmitDiwan

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

315 Views

The has() method in jQuery is used to return elements having one or more elements inside them, that matches the specified selector.SyntaxThe syntax is as follows−$(selector).has(ele)Above, the parameter ele is used to specify a selector expression or an element to match elements against.ExampleLet us now see an example to implement ... Read More

Display table records from a stored procedure in MySQL

AmitDiwan

AmitDiwan

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

1K+ Views

Let us first create a table −mysql> create table DemoTable1933    (    ClientName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1933 values('Chris Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1933 values('David ... Read More

Select items based on value first, then order on the basis of date for rest of the records in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:42:25

368 Views

Use ORDER BY to fix a record and then displayselect * from yourTableName order by yourColumnName1=yourValue desc, yourColumnName2;Let us first create a table −mysql> create table DemoTable1932    (    UserName varchar(20),    ShippingDate date    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using ... Read More

Extract the month and year in the following format: “mm-yyyy” (month year) along with all columns in MySQL?

AmitDiwan

AmitDiwan

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

729 Views

For month and year in a specific format, use DATE_FORMAT() along with STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable1931    (    ShippingDate varchar(40)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1931 values('10-11-2017'); ... Read More

MySQL query to add days with interval of 45 days and display the output in a new column

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 07:38:36

567 Views

For this, you can use date_add(). Let us first create a table −mysql> create table DemoTable1930    (    DueTime datetime    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1930 values('2017-10-21'); Query OK, 1 row affected (0.00 sec) ... Read More

Reset Primary Key in MySQL

AmitDiwan

AmitDiwan

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

629 Views

To reset primary key, at first use TRUNCATE table, then use ALTER TABLE. Let us first create a table −mysql> create table DemoTable1929    (    UserId int NOT NULL AUTO_INCREMENT,    PRIMARY KEY(UserId)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert ... Read More

Advertisements