Question: I have SQL Server 2012 with DB1 , DB2 , Db3 ...> DB50

If I need to view databases in server I use 

```
SELECT * FROM sys.databases   

```

All databases have same table `Saves` except for five databases that do not have this table.

I need to know which databases have table `Saves` - for this I use

```
sp_msforeachdb "SELECT '?' DatabaseName, Name FROM ?.sys.Tables WHERE Name LIKE '%saves%'"

```

How do I retrieve data from table `Saves` from all databases if found?

I use one by one and it takes a lot of time to save data like

```
select * from db1.dbo.Saves

```

and save data then back to search 

```
select * from db2.dbo.Saves

```

and save data then back to search

```
select * from db3.dbo.Saves

```

I need a SQL command like :

```
Select * from Saves in  sys.databases  if found

```

Answer: 
Disclaimer: I don't know how to use CodeIgniter, but this is what you do if you want to order by some custom order such as yours:

```
SELECT * FROM your_table WHERE id IN 
(5, 3, 8, 12, 30, 29, 26, 28, 4, 7) 
ORDER BY FIELD(id, 5, 3, 8, 12, 30, 29, 26, 28, 4, 7)

```

Now, if you know how to adjust this in CodeIgniter so it produces a query like this - your problem is solved via MySQL.
```
$this->db->where_in('id',$arrayIds);
$arrayList = implode(',',$arrayIds);
$this->db->order_by('FIELD(id,'.$arrayList.")");

```