user1627928
user1627928

Reputation: 313

SQL - Using the results of subquery in SELECT in the SELECT

Example:

SELECT
    (
        ...
    ) AS imageName,
    (
        ...
    ) AS imageURL,
    CONCAT(imageName, ' ', imageURL)

How could I achieve this?

Upvotes: 0

Views: 76

Answers (2)

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79919

You can do the following but watch out the tables' aliases:

   SELECT
     T.imageName, T.imageURL
     CONCAT(imageName, ' ', imageURL)
   FROM 
   (
       SELECT
      (
        ...
       ) AS imageName,
       (
        ...
      ) AS imageURL
       FROM ... AS innerT
   ) T

Upvotes: 1

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171391

You can do it all inside the CONCAT, like this:

select CONCAT(( select ... ), ' ', ( select ... )) 

Upvotes: 1

Related Questions