Question: I have 3 tables:

* terms: (term\_id...)
* tags: (tag\_id, tag\_name); and
* term\_tags (term\_id, tag\_id)

term\_tags is an intermediary table with a couple foreign key constraints to term\_id and tag\_id in the terms and tags tables respectively.

I am trying to pull the tags associated to a given term id using the PHP code below.

```
    <?php
    include('includes/config.php');
    $sql = "SELECT tag_name FROM tags JOIN term_tags WHERE term_id = ?";
    $stmt = $db->prepare($sql);
    if($stmt->execute(array($_GET['id']))){
        while($row = $stmt->fetch()){
            echo $row['tag_name'], "<br />";
        }
    }
    ?>

```

What happens is all rows are fetched from the tags table, I only want the tags associated with a given term id. I'm not sure if it's my SQL statement or my PHP, the PHP looks fine to me but I'm still kind of new to joins.

A little help?

Answer: 
Your query is already Linq. I'm guessing here, but I think you want to change it to fluent (or "method syntax"), if so, here is the direct *translation*:

```
db.PageLayouts.Where(x => x.ZoneName == zone.Name)
              .Join(db.PageLayouts,
                    l => l.PageId,
                    p => p.PageId,
                    (l,p) => new { l,p })
              .Where(z => x.p.ZoneName == PageName)
              .OrderBy(x => x.l.AppearanceOrder)
              .Select(x => x.l)
              .ToList();

```

I don't think your join makes a lot of sense, but I just changed the syntax from linq to fluent.

PS: this answer was crafted quickly and without thinking too much, handle with care
We have Query Syntax and Method Syntax in LINQ.See [this](https://msdn.microsoft.com/en-us/library/vstudio/bb397947.aspx).

```
//Query syntax:
IEnumerable<int> numQuery1 = 
    from num in numbers
    where num % 2 == 0
    orderby num
    select num;

//Method syntax:
IEnumerable<int> numQuery2 = numbers.Where(num => num % 2 == 0).OrderBy(n => n);

```

> 
> Most queries in the introductory Language Integrated Query (LINQ)
>  documentation are written by using the LINQ declarative query syntax.
>  However, the query syntax must be translated into method calls for the
>  .NET common language runtime (CLR) when the code is compiled. These
>  method calls invoke the standard query operators, which have names
>  such as Where, Select, GroupBy, Join, Max, and Average. You can call
>  them directly by using method syntax instead of query syntax.
> 
> 
>