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

  • Home
  • SEARCH
  • 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 9039553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:45:27+00:00 2026-06-16T09:45:27+00:00

select pck.id, pck.name, deb.last_time from (select id, name from dp_package where name like %s

  • 0

“select pck.id, pck.name, deb.last_time from (select id, name from dp_package where name like %s limit %s, %s) as pck left join (select package_id, last_time from dp_deb where id in (select max(id) from dp_deb group by package_id)) as deb on pck.id = deb.package_id” %(keyword, start, limit)

  • 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-06-16T09:45:28+00:00Added an answer on June 16, 2026 at 9:45 am

    Assuming the model is defined:
    Base = declarative_base()

    class Package(Base):
        __tablename__ = 'db_package'
        id = Column(Integer, primary_key=True)
        name = Column(String)
        def __init__(self, name):
            self.name = name
    
    class Deb(Base):
        __tablename__ = 'db_deb'
        id = Column(Integer, primary_key=True)
        package_id = Column(Integer, ForeignKey('db_package.id'))
        name = Column(String)
        last_time = Column(DateTime)
        def __init__(self, name, last_time):
            self.name = name
            self.last_time = last_time
    
        packages = relationship(Package, backref="debs")
    

    the code below should produce the same result (although different SQL query, where one subquery is replaced with simple LEFT OUTER JOIN):

    # query parameters
    keyword, start, limit = 'xxx', 1, 3
    
    # subquery for the last_time
    sq2h = session.query(Deb.package_id, func.max(Deb.id).label("max_id")).group_by(Deb.id).subquery("max_deb")
    sq2 = (session.query(Deb.package_id, Deb.last_time).
            join(sq2h, Deb.id == sq2h.c.max_id))
    sq2 = sq2.subquery("deb")
    
    qry = (session.query(Package.id, Package.name, sq2.c.last_time).
            outerjoin(sq2, sq2.c.package_id == Package.id).
            filter(Package.name.contains(keyword))
            )[start:(start + limit)]
    print qry
    

    producing this SQL for SQLite:

    SELECT  db_package.id AS db_package_id, 
            db_package.name AS db_package_name, 
            deb.last_time AS deb_last_time
    FROM    db_package 
    LEFT OUTER JOIN(SELECT  db_deb.package_id AS package_id, db_deb.last_time AS last_time
                    FROM    db_deb 
                    JOIN   (SELECT  db_deb.package_id AS package_id, 
                                    max(db_deb.id) AS max_id
                            FROM    db_deb 
                            GROUP BY db_deb.id
                           ) AS max_deb 
                      ON db_deb.id = max_deb.max_id
            ) AS deb 
        ON  deb.package_id = db_package.id
    WHERE   db_package.name LIKE '%%' || ? || '%%'
    LIMIT ? OFFSET ?
    
    ('xxx', 3, 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT gameratingstblx245v.gameid,avg( gameratingstblx245v.rating ) as avgrating, count(gameratingstblx245v.rating) as count,gamedata.name ,gamedata.gameinfo FROM gameratingstblx245v LEFT JOIN
select DISTINCT(cctv_id), cctv.[name] from points_cctv left join cctv on points_cctv.[cctv_id] = cctv.[id] I want
SELECT NameMonth,Year,Value from Table WHERE Name LIKE '%JERRY%' AND Year = (SELECT MAX(Year) FROM
SELECT rates_Calendar.date, subQuery.name, COALESCE(subQuery.amount,0) as amount, subQuery.reference, subQuery.property FROM rates_Calendar LEFT JOIN ( SELECT
SELECT * From `users` AS `User` LEFT JOIN `selections` AS `Selections` ON (`Selections`.`user_id` =
SELECT *, SUM( cardtype.price - cardtype.cost ) AS profit FROM user LEFT OUTER JOIN
select p.Id, sum(inc.Quantity) from Products p join Incomes inc group by p.Id order by
SELECT * FROM Customer WHERE Name 'LIKE [a-f]%' How Can I acheive this in
SELECT * FROM tableFoo LEFT JOIN tableBar ON tableFoo.commonColumn = tableBar.commonColumn WHERE tableBar.commonColumn IS
select sum(value) as 'Value',max(value) from table_name where sum(value)=max(sum(value)) group by id_name; The error is:

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.