Guest User

Untitled

a guest
Jan 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. mentor_id applicant_id mentor_count mento_email mentor_name mentor_pass
  2. 193 92 1 test@yahoo.com test 1234
  3. 194 92 2 table@yahoo.com table 4567
  4. 195 92 3 lamp@yahoo.com lamp 7890
  5. 196 92 1 test@yahoo.com test 1234
  6. 197 92 2 table@yahoo.com table 4567
  7. 198 92 3 lamp@yahoo.com lamp 7890
  8.  
  9. mf table:
  10.  
  11. mf_id mentor_id dept contact orgname yrs length sak social char goal resp emomat res others impact evaluation
  12. 43 193 math dept 9111111 etc 1 1 e e e e e e e e e good
  13. 114 196 math dept 9111111 etc 1 1 e e e e e e e e e good
  14. 193 197 sci dept 9222222 org 2 2 n n n n n n n n n medium
  15. 194 194 sci dept 9222222 org 2 2 n n n n n n n n n medium
  16. 220 195 eng dept 9333333 hello 3 3 q q q q q q q q q bad
  17.  
  18. SELECT *
  19. FROM mentor m1
  20. LEFT JOIN (
  21.  
  22. SELECT mentor_name, max( mentor_id ) AS maxid
  23. FROM mentor m
  24. GROUP BY m.mentor_id
  25. )m2 ON m1.mentor_name = m2.mentor_name
  26. AND m1.mentor_id < m2.maxid
  27. LEFT JOIN mf ON m1.mentor_id = mf.mentor_id
  28. WHERE m1.applicant_id =833
  29. AND m2.maxid IS NULL
  30. ORDER BY m1.mentor_id ASC
  31. LIMIT 0 , 30
  32.  
  33. mentor_id applicant_id mentor_count mentor_email mentor_name mentor_pass mentor_name maxid mf_id mentor_id dept contact orgname yrs length sak social char goal resp emomat res others spirit concept comm impact evaluation
  34. /*there is data here but the column for mentor_name onwards is null*/
  35.  
  36. select * from mentor
  37. where mentor_id in
  38. (
  39. SELECT max(mentor_id) from mf
  40. where applicant_id = 92
  41. group by mentor_id
  42. )
  43.  
  44. select *
  45. from mentor
  46. inner join
  47. (
  48. SELECT *, max(mentor_id) as maxid
  49. from mf
  50. group by mentor_id
  51. ) mf on mentor.mentor_id = mf.maxid AND mentor.application_id = mf.application_id
  52. where applicant_id = 92
Add Comment
Please, Sign In to add comment