When mixing 'and' and 'or' you must use brackets to show what you really mean e.g.
SELECT * FROM tbl_Device
(Num1 = '1' AND Num2 = '2' AND Num3 = '3' )
( Flag LIKE 'LastVersion' OR Flag LIKE 'OnlyVersion' )
As an aside there is no point in using 'LIKE' unless you are using a wildcard e.g.
You probably wanted to use
AND Flag IN ('LastVersion','OnlyVersion')
in which case you wouldn't have hit the and/or problem