---
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:
  - sqlmodel
  - sqlalchemy
  - orm
  - 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-image">
      <img src="https://sqlmodel.tiangolo.com/assets/images/social/tutorial/limit-and-offset.png" alt="Read a Range of Data - LIMIT and OFFSET - SQLModel — SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness." loading="lazy">
    </div>
    <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()
```



!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
