Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Resolve an error whenever multiple rows are returned in MySQL Benchmark?
You will get an error whenever you return multiple rows in the benchmark. Return a scalar value or single row instead of multiple rows. The syntax is as follows −
SELECT yourColumnName FROM yourTableName WHERE yourCondition.
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table UserDemo -> ( -> UserId int, -> UserName varchar(20), -> RegisteredCourse varchar(10) -> ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into UserDemo values(1,'John','Java'); Query OK, 1 row affected (0.16 sec) mysql> insert into UserDemo values(2,'Larry','C'); Query OK, 1 row affected (0.21 sec) mysql> insert into UserDemo values(3,'Carol','C++'); Query OK, 1 row affected (0.11 sec) mysql> insert into UserDemo values(4,'Mike','C#'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using a select statement. The query is as follows −
mysql> select *from UserDemo;
The following is the output −
+--------+----------+------------------+ | UserId | UserName | RegisteredCourse | +--------+----------+------------------+ | 1 | John | Java | | 2 | Larry | C | | 3 | Carol | C++ | | 4 | Mike | C# | +--------+----------+------------------+ 4 rows in set (0.00 sec)
Your benchmark error is as follows −
mysql> select benchmark(1000,(select RegisteredCourse from UserDemo)); ERROR 1242 (21000): Subquery returns more than 1 row
Since the subquery returned more than one row, therefore you need to return a single row. The query is as follows −
mysql> select RegisteredCourse from UserDemo where UserId=1;
The following is the output −
+------------------+ | RegisteredCourse | +------------------+ | Java | +------------------+ 1 row in set (0.00 sec)
Advertisements
