简体   繁体   中英

Multiple elements in sub-query

I am trying to write a query in the form of:

SELECT
   field_a.table AS x,
   field_b.table AS y,
   ( SELECT
       field_a.tableb AS a,
       field_b.tableb AS b,
    FROM tableb) FROM table

However, I get the following error message: Operand should contain 1 column(s)

Is there any way this can be done or will I have to resort to multiple sub-queries? I just see it as quite inefficient.

Cheers

For your proposed query to make any sense at all, it must be the case that table tableb has only one row. In that case, you can probably achieve your objective with a join instead of a subquery. Maybe this is what you want:

SELECT
  table.field_a AS x,
  table.field_b AS y,
  tableb.field_a AS a,
  tableb.field_b AS b
FROM
  table CROSS JOIN tableb

If in fact tableb has multiple rows, each correlated in some way with exactly one row of table , then you would instead perform an [INNER] JOIN using a join predicate corresponding to the appropriate relationship. If you want anything more specific then you'll need to describe your data better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM