Question: I am trying to track pageviews on my site whether a user is logged in or not and so I'm capturing the sessionId in my log. I only want to show tracking results for session ids that have at some point logged in and so my flow is as follows:

```
$pagestats = $wpdb->get_results("SELECT * FROM wp_user_stats WHERE uid=".$_GET['viewstats']);
$sessionArray = array();

foreach($pagestats as $checkSession)
{
    if( !(in_array($checkSession->sessionId, $sessionArray)))
    {
        $sessionArray[] = $checkSession->sessionId;
        }
    }

```

Next, I am trying to gather all of the stats concerning any session Ids generated by this particular user ...

```
$sessions = join(',',$sessionArray);
$pagestats = $wpdb->get_results("SELECT * FROM wp_user_stats WHERE `sessionId` IN($sessions)") or die(mysql_error());

```

This is the part that throws the error. The error is:

```
Unknown column 'sjhntmqhltknks8pbhr750voe7' in 'where clause'

```

I don't understand why it's trying to find a column that matches the session Id instead of a result within that column.

Answer: 
The problem is that the session id is not numeric and needs to be wrapped in quotes. Something like the following would add proper quote to your `$sessions` string:

`$sessions = "'" . implode("', '", $sessionArray) . "'";`

You should also make sure you are escaping any user supplied input (e.g. `$_GET['viewstats']`) before using them to help avoid SQL injection attacks. It wouldn't hurt to escape `$checkSession->sessionId` as you are adding it to the `$sessionArray` array either.

If you are using a framework (it looks like you may be using WordPress) read the manual for the database component as it may provide functions to handle some of this for you.
```
$pagestats = $wpdb->get_results("SELECT * FROM wp_user_stats WHERE `sessionId`=$sessions") or die(mysql_error());

```