Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mentor_id applicant_id mentor_count mento_email mentor_name mentor_pass
- 193 92 1 test@yahoo.com test 1234
- 194 92 2 table@yahoo.com table 4567
- 195 92 3 lamp@yahoo.com lamp 7890
- 196 92 1 test@yahoo.com test 1234
- 197 92 2 table@yahoo.com table 4567
- 198 92 3 lamp@yahoo.com lamp 7890
- mf table:
- mf_id mentor_id dept contact orgname yrs length sak social char goal resp emomat res others impact evaluation
- 43 193 math dept 9111111 etc 1 1 e e e e e e e e e good
- 114 196 math dept 9111111 etc 1 1 e e e e e e e e e good
- 193 197 sci dept 9222222 org 2 2 n n n n n n n n n medium
- 194 194 sci dept 9222222 org 2 2 n n n n n n n n n medium
- 220 195 eng dept 9333333 hello 3 3 q q q q q q q q q bad
- SELECT *
- FROM mentor m1
- LEFT JOIN (
- SELECT mentor_name, max( mentor_id ) AS maxid
- FROM mentor m
- GROUP BY m.mentor_id
- )m2 ON m1.mentor_name = m2.mentor_name
- AND m1.mentor_id < m2.maxid
- LEFT JOIN mf ON m1.mentor_id = mf.mentor_id
- WHERE m1.applicant_id =833
- AND m2.maxid IS NULL
- ORDER BY m1.mentor_id ASC
- LIMIT 0 , 30
- 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
- /*there is data here but the column for mentor_name onwards is null*/
- select * from mentor
- where mentor_id in
- (
- SELECT max(mentor_id) from mf
- where applicant_id = 92
- group by mentor_id
- )
- select *
- from mentor
- inner join
- (
- SELECT *, max(mentor_id) as maxid
- from mf
- group by mentor_id
- ) mf on mentor.mentor_id = mf.maxid AND mentor.application_id = mf.application_id
- where applicant_id = 92
Add Comment
Please, Sign In to add comment