I want to get only specific column details from ActiveRecord.
So I did run the following code.

```
accounts = self.accounts(:select => "id, name,account_number").order("created_at DESC").paginate(:page => page_count, :per_page => per_page_count)

```

Whenever this line is getting executed its firing this following query

```
SELECT "accounts".* FROM "accounts" INNER JOIN "super_account_accounts" ON "accounts"."id" = "super_account_accounts"."account_id" WHERE "super_account_accounts"."super_account_id" = 8 ORDER BY accounts.created_at DESC LIMIT 10 OFFSET 0

```

Why it is getting all the column information when I have already specified few of the columns for which I want the info.

NOTE:-

Super account model has the following association with account

```
has_many :accounts, :through => :super_account_accounts, :dependent => :destroy

```

account model has the following association with super account

```
has_many :super_accounts, :through => :super_account_accounts

```

**EDIT 1**

So got it working by using the following 

```
    accounts = self.accounts.select("id, name,account_number").order("created_at DESC").paginate(:page => page_count, :per_page => per_page_count)

```

Lets say i want to fetch 10-11 columns.
after using the above query, when i tried to apply to\_json method its only taking some of the columns into consideration while ignoring rest of the columns.

Any inputs on why such thing is happening with to\_json method?
Am i missing something?

**EDIT2**
got the to\_json thing working by writting the following code

```
account.to_json({ :only => [:id, :name, :account_number, :column4, :column5, :column8, :column9] })

```

Still Am not sure why we need to specify the column names inside to\_json method as we are already getting that from the select query.very strange