vendredi 10 juillet 2015

Sql Query On Joining 3 tables

I created 3 table as follows

Table Student1:

id  status  amount    Name            date
1     0      4500     ram           04/02/2012
2     0      2000    shyam          05/09/2013
4     0      1500    ghanshyam      08/11/2014

Table Student2:

id   status   amount    Name          date
3      0      4500     gopal       04/02/2012
2      0      8000   radheshyam    15/11/2013
4      1      1500    ghanshyam    18/10/2015

Table Student3:

id   status   amount    Name          date
1      1      4500     ram         04/02/2012
2      0      6500     radhe       11/11/2014
3      1      4500     gopal       04/02/2012

Excepted Result Condition:

1)Select Records with unique "id" from combining 3 tables.

2)Update Field "date" of corresponding record if status=1 of same record with same name,amount in any of the 3 Tables.

3)If 2 or more than 2 record after combining 3 tables with same "id" but other fields different(i.e. Same id but different name,amount,date) then add all them to final result but my appending 1,11,111 to them.

Final Result To be Expected:

id  status  amount    Name            date
1     1      4500     ram           04/02/2012
2     0      2000    shyam          05/09/2013
21    0      8000   radheshyam      15/11/2013
211   0      6500     radhe         11/11/2014
3     1      4500     gopal         04/02/2012
4     1      1500    ghanshyam      18/10/2015

Aucun commentaire:

Enregistrer un commentaire