Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 592283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:43:25+00:00 2026-05-13T15:43:25+00:00

Suppose I have the following tables: Articles with fields article_id , title Tags with

  • 0

Suppose I have the following tables:

  • Articles with fields article_id, title
  • Tags with fields tag_id, name
  • ArticleTags with fields article_id, tag_id

And I wish to find all articles that have a given tag. How do I create this complicated join in SQLAlchemy?

In SQL it would look like:

SELECT a.article_id, a.title FROM Articles AS a
JOIN ArticleTags AS at ON a.article_id  = at.article_id
JOIN Tags        AS t  ON at.tag_id = t.tag_id
WHERE t.name = 'tag_name'

I can’t figure out how to do it in SQLAlchemy. I am using ArticleTags as “secondary” table only and I can’t figure out how to involve it in the JOIN.

Can anyone help?

Thanks, Boda Cydo.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:43:26+00:00Added an answer on May 13, 2026 at 3:43 pm

    Assuming that you set the ForeignKey constraints correctly and created mappers:

    q = Session.query(Articles).filter(Articles.article_id == ArticleTags.article_id).\
        filter(ArticleTags.tag_id == Tags.tag_id).\
        filter(Tags.name == 'tag_name')
    

    If you have setup a Many-to-Many relation it’s even more simple:

    q = Session.query(Articles).filter(Articles.tags.any(name = 'tag_name'))
    

    For some more examples for blog-related queries look here.

    If you use the sql expression language, it should be straight forward translateable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following tables in my database: Now all my queries depend
I have the following tables; CREATE TABLE IF NOT EXISTS `tags` ( `tag_id` int(11)
In SQL server 2008: Suppose I have two tables. Table1 has 3 fields: Name,
Suppose i have the following 2 SQL tables: Foo Column DataType --------------------------- Title NVARCHAR(20)
Suppose you have to following tables where a sale consists of products and a
Suppose I have the following three tables expressing a relationship where posts are given
Here's my situation.. Suppose you have the following model entities, which represent single tables
Suppose I have the following table: PARAMETER - NAME varchar2(10) - TABLE_NAME varchar2(50) -
I use SQL Server 2000. Suppose I have two tables like the following: Area
Suppose i have the following tables : projects( project_id , project_name ) documents( document_id,document_name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.