<p>To get the basic utxo you would get from <code>query utxo</code>, you want a join from utxo_view to tx table.</p>
<p><code>SELECT * FROM utxo_view INNER JOIN tx ON tx.id = utxo_view.tx_id WHERE address = 'addr1...'</code></p>
<p>To get the list of txins sending the tx, you need to join that to tx_in and then rejoin that to the tx_out table and it will return a row for every output that's being used as an input, but usually at this point of complexity with SQL queries I start to throw for loops into my code.</p>

CC BY-SA 4.0
2021-10-04T16:31:57.850Z
2021-10-04T16:31:57.850Z
Samuel Leathers
<p>How can I query the last UTxO from an address on PostgreSQL (I used <code>cardano-db-sync</code>) like I would do using cardano-cli:</p>
<blockquote>
<p>cardano-cli query utxo --address addr_test1vpm4uhupwxc4jjea6c6s5p0t80znlfr03xj4ewygnjtxd3cyjdv8x --testnet-magic 1097911063</p>
</blockquote>
<p>I also want to know more information regarding this transaction like who sent, etc.</p>
<p>Thank you very much.</p>

CC BY-SA 4.0
2022-01-04T09:39:48.023Z
Hi, did you ever find an answer to his? I have the exact same query from cardano-db-sync but have not found a way to do this - thanks
simon
<cardano-cli><cardano-db-sync>
Query UTxO with PostgreSQL (cardano-db-sync)
# Query UTxO with PostgreSQL (cardano-db-sync)

(Asked by: username_0 on 2021-09-04)

How can I query the last UTxO from an address on PostgreSQL (I used `cardano-db-sync`) like I would do using cardano-cli:

> cardano-cli query utxo --address addr\_test1vpm4uhupwxc4jjea6c6s5p0t80znlfr03xj4ewygnjtxd3cyjdv8x --testnet-magic 1097911063

I also want to know more information regarding this transaction like who sent, etc.

Thank you very much.

**Tags:** cardano-cli, cardano-db-sync
> **Comments:**
> **username_1**: Hi, did you ever find an answer to his? I have the exact same query from cardano-db-sync but have not found a way to do this - thanks  

---

## 1 answers

### Answer by username_2 on 2021-10-04. Score: 4 | Accepted answer

To get the basic utxo you would get from `query utxo`, you want a join from utxo\_view to tx table.

`SELECT * FROM utxo_view INNER JOIN tx ON tx.id = utxo_view.tx_id WHERE address = 'addr1...'`

To get the list of txins sending the tx, you need to join that to tx\_in and then rejoin that to the tx\_out table and it will return a row for every output that's being used as an input, but usually at this point of complexity with SQL queries I start to throw for loops into my code.


---

