Getting "subquery returns more than one row" error whenever trying to join a column from another table as alias?

mikaeel

I am stuck with this problem for a whole 2 days. I have a users table and it contains:

+--------+--------+----------+--------------------------------------------+
| userId |  name  | username |          profile_pic                       |
+--------+--------+----------+--------------------------------------------+
|      1 | john   | john123  | http://localhost/profile_pic/user1pic.jpg  | 
|      2 | andrew | andrew   | http://localhost/profile_pi/user2pic.jpg   |
|      3 | doe    | doe      | http://localhost/profile_pic/user3pic.jpg  |
+--------+--------+----------+--------------------------------------------+

I have another table called userpost which contains:

+--------+--------+-------------+----------------------------+
| postId | userId | postMessage |         postImage          |
+--------+--------+-------------+----------------------------+
|      1 |      1 | "Hey"       | http://localhost/post1.jpg |
|      2 |      3 | "Add me"    | http://localhost/post2.jpg |
|      3 |      2 | "boring"    | http://localhost/post3.jpg |
+--------+--------+-------------+----------------------------+

userId is refrenced to users.userId. I am trying to join profile_pic to userpost but mysql is returning error. Here is what I am doing:

 SELECT *, (SELECT profile_pic FROM users 
 INNER JOIN userpost on users.userId = userpost.userId) as profile_pic FROM userpost

But getting Subquery returns more than 1 row error

I know I am doing something stupid with the query. I just want something like this:

 +--------+--------+-------------+----------------------------+--------------------------------------------+    
 | postId | userId | postMessage |         postImage          |    profile_pic                             |
 +--------+--------+-------------+----------------------------+--------------------------------------------+
 |      1 |      1 | "Hey"       | http://localhost/post1.jpg | http://localhost/profile_pic/user1pic.jpg  | 
 |      2 |      3 | "Add me"    | http://localhost/post2.jpg | http://localhost/profile_pic/user3pic.jpg  | 
 |      3 |      2 | "boring"    | http://localhost/post3.jpg | http://localhost/profile_pi/user2pic.jpg   |
 +--------+--------+-------------+----------------------------+--------------------------------------------+

I am having a meeting tomorrow to showcase my prototype app. Help will be appreciated.

user5992977

You are using a sub query not a join. When using subquery in the select, you have to make sure it returns exacly one row like

SELECT COL1,COL2,(SELECT 1) from YourTable

Or by using a correlated query, which I assume was your purpose but is not required since its from the same table as you select, so just use a simple join:

SELECT s.*, t.profile_pic
FROM users t 
INNER JOIN userpost s on t.userId = s.userId

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting' ORA-01427: single-row subquery returns more than one row' Error

From Dev

Select From one table : single-row subquery returns more than one row

From Dev

trying to use subquery but subquery returns more than one row with qualifiers

From Dev

Avoid the error -- Subquery returns more than one row

From Dev

Solving "single-row subquery returns more than one row" error in Oracle SQL

From Dev

ORA-01427: single-row subquery returns more than one row error

From Dev

Single-row subquery returns more than one row error for COUNT() function

From Dev

Solving "single-row subquery returns more than one row" error in Oracle SQL

From Dev

SQL Server / Report Builder subquery returns more than one row error

From Dev

Oracle SQL: Case Statement in where clause returns an error "single-row subquery returns more than one row"

From Dev

cascading Input Control sql query return error: "ORA-01427: single-row subquery returns more than one row"

From Dev

How can i resolve an ORA-01427 error (Single-row subquery returns more than one row)?

From Dev

Using a nested SELECT to retrieve multiple rows always returns ORA-01427 (Subquery returns more than one row) error or Missing Element Error

From Dev

subquery returns more than one row

From Dev

LAST INSERT ID SQL Subquery returns more than one row

From Dev

SQL single-row subquery returns more than one row

From Dev

Oracle - single-row subquery returns more than one row

From Dev

MySQL subquery returns more than one row selecting count with subquery

From Dev

Single-row subquery returns more than one row issue

From Dev

MySQL subquery returns more than one row when using not equal

From Dev

LAST INSERT ID SQL Subquery returns more than one row

From Dev

Single row subquery returns more than one row SQL Oracle

From Dev

How to fix Ora-01427 single-row subquery returns more than one row in select?

From Dev

Select Case Statment single-row subquery returns more than one row

From Dev

ORA-01427 single-row subquery returns more than one row

From Dev

Single-row subquery returns more than one row - SQL Query

From Dev

single-row subquery returns more than one row Oracle Database

From Dev

ORA-01427: single-row subquery returns more than one row ,,WHEN USING SELECT COUNT

From Dev

Oracle SQL Insert Single Row Subquery returns more than one row

Related Related

  1. 1

    Getting' ORA-01427: single-row subquery returns more than one row' Error

  2. 2

    Select From one table : single-row subquery returns more than one row

  3. 3

    trying to use subquery but subquery returns more than one row with qualifiers

  4. 4

    Avoid the error -- Subquery returns more than one row

  5. 5

    Solving "single-row subquery returns more than one row" error in Oracle SQL

  6. 6

    ORA-01427: single-row subquery returns more than one row error

  7. 7

    Single-row subquery returns more than one row error for COUNT() function

  8. 8

    Solving "single-row subquery returns more than one row" error in Oracle SQL

  9. 9

    SQL Server / Report Builder subquery returns more than one row error

  10. 10

    Oracle SQL: Case Statement in where clause returns an error "single-row subquery returns more than one row"

  11. 11

    cascading Input Control sql query return error: "ORA-01427: single-row subquery returns more than one row"

  12. 12

    How can i resolve an ORA-01427 error (Single-row subquery returns more than one row)?

  13. 13

    Using a nested SELECT to retrieve multiple rows always returns ORA-01427 (Subquery returns more than one row) error or Missing Element Error

  14. 14

    subquery returns more than one row

  15. 15

    LAST INSERT ID SQL Subquery returns more than one row

  16. 16

    SQL single-row subquery returns more than one row

  17. 17

    Oracle - single-row subquery returns more than one row

  18. 18

    MySQL subquery returns more than one row selecting count with subquery

  19. 19

    Single-row subquery returns more than one row issue

  20. 20

    MySQL subquery returns more than one row when using not equal

  21. 21

    LAST INSERT ID SQL Subquery returns more than one row

  22. 22

    Single row subquery returns more than one row SQL Oracle

  23. 23

    How to fix Ora-01427 single-row subquery returns more than one row in select?

  24. 24

    Select Case Statment single-row subquery returns more than one row

  25. 25

    ORA-01427 single-row subquery returns more than one row

  26. 26

    Single-row subquery returns more than one row - SQL Query

  27. 27

    single-row subquery returns more than one row Oracle Database

  28. 28

    ORA-01427: single-row subquery returns more than one row ,,WHEN USING SELECT COUNT

  29. 29

    Oracle SQL Insert Single Row Subquery returns more than one row

HotTag

Archive