Question: I have a tablet app with a Master / Detail layout, with a TableView in the Master panel that changes the content of the Detail pane. I'd like to have the master's row stay highlighted when clicked like it does in the android OS settings.

Right now the best I'm able to do is set the `backgroundColor` to a new color in response to a `'click'` event. However, when I do a quick tap, the row highlights, then blinks back to normal before highlighting again. I'm guessing this is the delay between when I lift my finger off and when the backgroundColor gets changed.

```
tableview.addEventListener('click', function(e) {
    ...
    else if (e.rowData.id == 3) { // scan history
        e.row.backgroundColor = 'blue';

```

This appears to be the way others have done it: <http://developer.appcelerator.com/question/124359/android---tableviews-deselectrow>

And if I was just using android and not Titanium: [How can I highlight the table row on click ?](https://stackoverflow.com/questions/4075356/how-can-i-highlight-the-table-row-on-click)

Answer: 
You can use a `left outer join` onto Table2, and then [`COALESCE`](http://msdn.microsoft.com/en-us/library/ms190349.aspx) the Alias and Name results like this:

```
SELECT Table1.ID, COALESCE(Table2.Alias, Table1.Name) AS Name, 
    Table1.Location
FROM Table1
LEFT OUTER JOIN Table2 ON Table1.ID = Table2.ID AND Table2.AliasType = 2

```

`COALESCE` works by finding the first non-null value in the supplied values.
Try something like this -- you just need to use `CASE`:

```
SELECT T1.Id, 
   CASE WHEN T2.Alias IS NOT NULL THEN T2.Alias ELSE T1.Name END as Name,
   t1.Location
FROM Table1 T1
   LEFT JOIN Table2 T2 ON T1.Id = T2.Id AND T2.AliasType = 2

```

Here is the [SQL Fiddle](http://sqlfiddle.com/#!3/8efa3/1).

Good luck.