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 6747315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:25:38+00:00 2026-05-26T12:25:38+00:00

I have a small database which is legacy from an almost defunct project. This

  • 0

I have a small database which is legacy from an almost defunct project. This database has a “Patients” table with individual personal data and an unique “Id” field, and an “Exams” table with some fields for each exam, one of these fields being “Patient_Id”.

What I want is, for a given patient (row from “Pacientes” table) the exams (rows) from “Exames” table whose “Patient_Id” matches that of the given patient.

I am very beginner with SQL, so if the question is very naive, I apologize.

My working code is the following, but I am using a for loop while I would much rather have a SQL query (which is the very point of using databases, I think…):

#!/usr/bin/env python
# coding: utf-8

import os, sqlite3

conn = sqlite3.connect('BDdata.db3')
conn.row_factory = sqlite3.Row
c = conn.cursor()

c.execute('SELECT * FROM Exames')
exams = c.fetchall()

c.execute('SELECT * FROM Pacientes')
for row in c:
    Nome = row['nome']
    ID = row['Id']
    for exam in exams:          # I would like to replace this loop
        if exam['Id_Paciente'] == ID:       # with a SQL query meaning
            print exam['File']

============================

An answer to a similar question seems to be what I want, but I have no idea how to do this in Python with sqlite3 module, much less what in this expression is essential and what is incidental, or what is the syntax structure:

Selecting rows from a table by One a field from other table

SELECT i.prof_image 
FROM profile_images i 
WHERE cat_id = (select max(cat_id) from images_cat)
  • 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-26T12:25:39+00:00Added an answer on May 26, 2026 at 12:25 pm

    I think the following should do what you want:

    ...
    c = conn.cursor()
    
    c.execute('SELECT * FROM Pacientes')
    for row in c.fetchall():
        Nome = row['nome']
        ID = row['Id']
        c.execute('SELECT File FROM Exames WHERE Id_Paciente=?', [ID])
        for exam in c:
            print exam['File']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application which reads from a Oracle 9i database and sends
I have a small application which has around 38 tables in the Database (SQL
I have a small database with tables containing a small amount of data which
I have a small image from a database and the image's average color need
I have small page which has label, DropDownList and a submit button. <div> <asp:label
I'm making a small DataBase with MySQL Workbench. I have a main table, called
I have a small project for which I need to offer a CMS UI/storage
I have a SQL Server 2005 database from which I'm removing several large tables
We have a large database on which we have DB side pagination. This is
I have small database of business and their addresses. Using the Google Geocode API

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.