Design SQL Query for following case

Posted by rs on Stack Overflow See other posts from Stack Overflow or by rs
Published on 2010-01-11T17:19:11Z Indexed on 2010/05/17 2:30 UTC
Read the original article Hit count: 276

Filed under:
|
|
|

Consider tables

Table1
id, name
1   xyz
2   abc
3   pqr

Table2
id title
1  Mg1
2  Mg2
3  SG1

Table3
Tb1_id  tb2_id  count
1         1      3
1         2      3
1         3      4
2         2      1
3         2      2
3         3      2


I want to do query to give result like
id     title
1       MG1
2       MG2
3       Two or More Title

MG1 has higher preference if MG1 and count >= 1 then it is given as MG1 title , for others corresponding title is used and for count > 1 as two or more

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server