sql - Select 2 Rows from Table when COUNT of another table -


Here's the code I have:

  SELECT `A`. * FROM 'A', 'A' on 'B' `A_ID` =` b``` value_1``````` where `b` is` value_2` and 'b' isusirid '' rand (No. 2  

currently What this is going to do, this selection is made to 2 rows with A , when 2 rows A_id is not selected value_1 or < Code> value_2 in b and b are different for different users with the rows user id .

Whatever I have to do, he too has to do this so that he also knows Does it already match in B with A_id (either in value_1 , or value_2 ) And userid , and if the N is more than the line, then it does not select the A line.

The following will handle your first request:

  choose ... to be included on the left (bevelui = aa_id or bevalue_2 = a .adid) and bisirid = @ osirid where B & L; Non-worthless columns & gt; The tap is  

The part of the move is taking your criteria into the link of joining the left. I'm not sure that the second part of your request fits with the first part. If there are no rows in B that is a match for value for that user on value_1 or value_2, then the line number will be zero according to the definition. Is it that you want this to be the situation where B can have maximum Range of Matches on the given criteria? If so, then I will type my query in such a way:

  Select from where one (from BB2 select number (*) where (B2 .value_1 = AA_ID or B2. Value_2 = A.A_id) and B2.userid = @userid) & lt; = @MaxItems  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -