---
title: "Read a Range of Data - LIMIT and OFFSET - SQLModel"
description: "!https://sqlmodel.tiangolo.com/tutorial/limit-and-offset/"
date: 2024-01-12
published: true
tags:
  - database
  - orm
  - python
  - sqlalchemy
  - sqlmodel
  - thought
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://sqlmodel.tiangolo.com/tutorial/limit-and-offset/" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-content">
      <div class="embed-card-title">Read a Range of Data - LIMIT and OFFSET - SQLModel</div>
      <div class="embed-card-description">SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.</div>
      <div class="embed-card-meta">sqlmodel.tiangolo.com</div>
    </div>
  </a>
</div>


Today I was running some sqlmodel queries through the sqlalchemy orm.  Admittedly I've not done enough orm queries before, and I've done quite a bit of raw sql. I was trying to get objects from two separate models that had relationships setup.

``` python
session.query(User, Images).where(User.id == 3).all()
```

It is incredibly slow, and gives me the following warning.

``` python
SELECT statement has a cartesian product between FROM element(s)
```

What I learned from the SQLModel docs is that you should give it a join to correct this and go much faster.

``` python
session.query(User, Images).join(Images).where(User.id == 3).all()
```


