diff --git a/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg b/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
index 328f846..10d4edc 100644
--- a/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
+++ b/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
@@ -87,25 +87,19 @@ getAccountByKey() ::= <<
>>
searchAccounts(searchKey, offset, rowCount) ::= <<
-select SQL_CALC_FOUND_ROWS <allTableFields()>
-from (
- select <allTableFields()>
- from accounts
- where name like ('%<searchKey>%') <AND_CHECK_TENANT()>
- union
- select <allTableFields()>
- from accounts
- where email like ('%<searchKey>%') <AND_CHECK_TENANT()>
- union
- select <allTableFields()>
- from accounts
- where external_key like ('%<searchKey>%') <AND_CHECK_TENANT()>
- union
- select <allTableFields()>
- from accounts
- where company_name like ('%<searchKey>%') <AND_CHECK_TENANT()>
-) results
-order by results.record_id
+select SQL_CALC_FOUND_ROWS
+<allTableFields("t.")>
+from <tableName()> t
+where 1 = 1
+and (
+ <idField("t.")> = '<searchKey>'
+ or t.name like '%<searchKey>%'
+ or t.email like '%<searchKey>%'
+ or t.external_key like '%<searchKey>%'
+ or t.company_name like '%<searchKey>%'
+)
+<AND_CHECK_TENANT("t.")>
+order by <recordIdField("t.")> ASC
limit :offset, :rowCount
;
>>
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
index e559557..5c0542e 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
@@ -319,6 +319,11 @@ public class TestAccount extends TestJaxrsBase {
}
private void searchAccount(final AccountJson input, @Nullable final AccountJson output) throws Exception {
+ // Search by id
+ if (output != null) {
+ doSearchAccount(input.getAccountId(), output);
+ }
+
// Search by name
doSearchAccount(input.getName(), output);