Skip to content
Advertisement

What is the issue in below sql query? [closed]

I am beginner in sql. Anyone please tell me the problem of my customised query.

Error Code: 1241. Operand should contain 1 column(s)

Subscription table

Advertisement

Answer

You should put that subquery with the max and group by inside an INNER JOIN clause.

Since I don’t have your data tables, I made up one environment to test that query by using table variables. The example below is for SQL Server, but the query works fine for MySQL, which currently I don’t have installed on my machine.

Now populate tables with data:

Then, I test the query against these data

Note that using subquery as a view in INNER JOIN, I should add an alias name for max(expireDate) column. The result is:

id hospital_active maxexpiredate hospitalId
145 1 2021-07-10 00:00:00.000 145
146 1 2021-10-10 00:00:00.000 146
147 1 2021-09-10 00:00:00.000 147

Is that what you want?

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement