0

Am trying this query to get result. but am not able to find any results. I don't know where i did the mistake.

Select * from loadcell_transaction_log where id = 

(SELECT  max(id) as id1
  FROM [addpro].[dbo].[loadcell_transaction_log] group by line2_count);

This is the error am getting:

Msg 512, Level 16, State 1, Line 2 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

1
  • The query you posted is not MySQL. Also the error message. They are probably MSSQL. Please use the correct tags. Commented Nov 28, 2017 at 10:52

2 Answers 2

2

Try this:

Select * from loadcell_transaction_log where id IN

(SELECT  max(id) as id1
  FROM [addpro].[dbo].[loadcell_transaction_log] group by line2_count);

I replace '=' with the keyword 'IN' which allows for multiple results in the subquery.

Sign up to request clarification or add additional context in comments.

Comments

1

using group by with max(id) will return max(id) for each line2_count :

select * from 
  (select log.*,row_number() over (partition by line2_count order by id desc ) rn FROM [addpro].[dbo].[loadcell_transaction_log] as log)
  where rn = 1;

If you want to check only for max(id) in the full table data then dont use group by clause else use in clause as referred by @farbiondriven.

6 Comments

Probably because you just make a comment and say what has already been answered. Duplicating answers makes no sense, you should perhaps find a different solution and people will not downvote.
that makes sense. Before someone answers, I had already typed my answer so just posted it. Will keep in mind next time. :)
Perhaps just change the answer to something a little different than the first answer so it is a second option.
There you go. Downvote retracted and you gained a vote.
This encouraged me to write more answers :D
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.