0
votes

UPDATE Consider 2 Tables.

Events Table. eventID int pk status1 int status2 int

Status Table ID int pk statusName varchar

now each events has 2 statuses written in int. And I want to show event rows on the screen but to get corresponding status name from Status table. Thus I have to join events table 2 times to status table. using status1,status2 ints to ID of status table.

While using entity framework I was writing such code

 join ds1 in db.Status on te.aStatus equals ds1.ID
 join ds2 in db.Status on te.bStatus equals ds2.ID
select new {
 Status1 = ds1.statusName,
 Status2 = ds2.statusName,
}

But now for some reasons I don't want to use Entity Framework , instead of that I want to write this directly in SQL I can join 2 dbs easely by

    SELECT db.Status.statusName FROM db.Main INNER JOIN
 Status ON dbo.Main.aStatus = dbo.Status.ID" 

and this will work. but how can I make second join ?

After SELECT I take this DataTable Object and get rows in loop. And in that loop I create from that rows List. And there I must get 2 statuses

        foreach (DataRow item in dtbProduct.Rows)
            {
                StatusList.Add(new JStatus()
                {
Status1= item["statusName"]  ???
Status2=item["statusName"]  ???

How can I get here 2 variables for each status ?

2
SELECT columns FROM t1 JOIN t2 ON condition(s) JOIN t3 ON condition(s) ... WHERE ...jarlh
how can I write those columns after select ?David

2 Answers

0
votes

does you find something below

 SELECT ds1.statusName,ds2.statusName FROM 
 db.Main d
 join db.Status ds1   on d.aStatus = ds1.ID
 join db.Status ds2   on d.bStatus = ds2.ID
0
votes
  $first_status = select status.statusName , events.* from status
    join events on events.status1 = status.id


    $second_status = select status.statusName, events.* from status
    join events on events.status2 = status.id

    foreach($first_status as $key =>status1){

     foreach($second_status as $k=>status2){
      if($first_status[$key]['id']== $second_status[k]['id']){
          $first_status[$key]['second_status']= $status2[$k][statusName]; 
      }
     }
    }

Sorry it may help you a little. I just tried to do it with multiple data variables.