-3

I got this error message when I tried to run this code

select *
from Folio_Guest
where FolioID = (
    select *
    from Folio
    where ArrivalDate between '20190101' and '20210901'
)
Dale K
  • 25,246
  • 15
  • 42
  • 71

1 Answers1

0

The subquery needs to return at most one row and only one column. Perhaps you intend something like this:

select fg.*
from Folio_Guest fg
where fg.FolioID in (select f.folioID
                     from Folio f
                     where ArrivalDate between '20190101' and '20210901'
                    );

The important changes are:

  • The subquery returns just one column, the one that should match to folioID.
  • The comparison uses in rather than = so it can match multiple rows, if appropriate.
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786