AmitDiwan has Published 10744 Articles

MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:36:06

1K+ Views

Let us first create a table &mnus;mysql> create table DemoTable (    `timestamp` timestamp ); Query OK, 0 rows affected (1.12 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(now()); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('00:00:00'); Query OK, 1 ... Read More

MySQL group_concat to add a separator for empty fields?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:33:08

425 Views

For this, you can use replace() along with group_concat(). Here, for empty fields, we are displaying a comma as a separator. Let us first create a table −mysql> create table DemoTable (    Id int,    Number varchar(100) ); Query OK, 0 rows affected (2.03 sec)Insert some records in the ... Read More

How to ORDER BY DESC and display the first 3 records in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:29:43

647 Views

For this, you can use ORDER BY DESC with LIMIT. Let us first create a table −mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(100) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert ... Read More

MySQL ORDER BY strings with underscore?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:27:27

330 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John_Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, ... Read More

HTML onresize Event Attribute

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:26:46

119 Views

The HTML onresize attribute is triggered when user resize the browser window.SyntaxFollowing is the syntax −Let us see an example of HTML onresize event Attribute −Example Live Demo    body {       color: #000;       height: 100vh;       background: linear-gradient(62deg, #FBAB7E 0%, ... Read More

Insert multiple rows from another table but the inserted records should be distinct

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:24:07

282 Views

For this, you can use DISTINCT along with the INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1 (    Value int ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(50); Query OK, ... Read More

HTML onpaste Event Attribute

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:22:51

237 Views

The HTML onpaste attribute is triggered when user paste some content in an HTML element in an HTML document.SyntaxFollowing is the syntax −Let us see an example of HTML onpaste event Attribute −Example Live Demo    body {       color: #000;       height: 100vh; ... Read More

Limit the count using GROUP BY in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:20:43

1K+ Views

Let us first create a table −mysql> create table DemoTable (    UserId int,    UserMessage varchar(100) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 'Hi'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable ... Read More

How to get MySQL query result in same order as given by IN clause?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:18:18

1K+ Views

For this, you can use IN() along with ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(100) ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> ... Read More

How to display all the MySQL tables in one line?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:15:49

554 Views

Use information_schema.tables to display all the tables. With that, se the database name as well, so that you can display tables only from a specific database.Let us now display all the tables in the database “web” −mysql> select group_concat(table_name) from information_schema.tables where table_schema='web';This will produce the following output −+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ... Read More

Advertisements