Question: I suppose this is more or less trivial thing but here it goes...

I have few relational tables and I'm trying to retrieve rows depending on 2 values. Here's my query so far:

```
SELECT `inventory`.*, `tags`.*, `tags_inv`.*, `categories`.*, `categories_inv`.*
FROM (`tags`)
LEFT JOIN `tags_inv` ON `tags_inv`.`tag_id` = `tags`.`tag_id`
LEFT JOIN `inventory` ON `inventory`.`inventory_id` = `tags_inv`.`inv_id`
LEFT JOIN `categories_inv` ON `categories_inv`.`inv_id` = `inventory`.`inventory_id`
LEFT JOIN `categories` ON `categories`.`cat_id` = `categories_inv`.`cat_id`
WHERE `categories`.`cat_id` = 1
AND  `inventory`.`inv_name`  LIKE '%p%'
OR  `inventory`.`inv_dim_w`  LIKE '%p%'
OR  `inventory`.`inv_dim_l`  LIKE '%p%'
OR  `inventory`.`inv_dim_h`  LIKE '%p%'
OR  `tags`.`tag_description`  LIKE '%p%'
ORDER BY `inventory`.`inv_name`

```

The problem is that my query selects everything from my db (like it is ignoring `cat_id`), but I would like to select only rows with `cat_id` 1 in this case...  

Is there a quick and reasonable way to resolve this? :)

Thanks in advance!

Answer: 
One way would be to create a [`FileStream`](http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx) with the [`FileMode.Append`](http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx) creation mode.

> 
> Opens the file if it exists and seeks to the end of the file, or
>  creates a new file.
> 
> 
> 

This would look something like:

```
public static void AppendAllBytes(string path, byte[] bytes)
{
    //argument-checking here.

    using (var stream = new FileStream(path, FileMode.Append))
    {
        stream.Write(bytes, 0, bytes.Length);
    }
}

```
You can also use the built-in `FileSystem.WriteAllBytes Method (String, Byte[], Boolean)`.

```
public static void WriteAllBytes(
    string file,
    byte[] data,
    bool append
)

```

Set append to **True** to append to the file contents; **False** to overwrite the file contents. Default is False.