문제

I need to perform the following query:

SELECT ID FROM tbl_a WHERE (fld_merchID, 'something') IN
(SELECT MerchID, MAX(Priority) FROM tbl_b WHERE Name LIKE 'AAA.com')

as you can image, there's no 'Priority' field in tbl_a. (I need to select the MerchID with the higher Priority value).

That query is returning empty and it shouldn't.

I'm not sure how to do it.

Thanks!

도움이 되었습니까?

해결책

If you want the one with the max priority, then you need to change your subquery pretty significantly to choose the MerchID with the highest priority:

SELECT ID FROM tbl_a WHERE fld_merchID IN (
  SELECT DISTINCT MerchID
  FROM tbl_b
  INNER JOIN (
    SELECT Name, MAX(Priority) as Priority
    FROM tbl_b 
    WHERE Name LIKE 'AAA.com'
    GROUP BY Name
  ) mx ON mx.Name = tbl_b.Name AND mx.Priority = tbl_b.Priority
)

다른 팁

try this ,

 SELECT ID FROM tbl_a WHERE fld_merchID IN
(SELECT MerchID, MAX(Priority) FROM tbl_b  WHERE Name LIKE 'AAA.com')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top