Results 1 to 20 of 21

Thread: Complex query in QSqlQuery

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Complex query in QSqlQuery

    Just a side note - I'd use a different query (it may be invalid but I mean the general idea):

    sql Code:
    1. SELECT
    2. MAX(cardid)+1 AS 'id',
    3. t.date,
    4. o.name,
    5. t.amount
    6. FROM `transactions` AS t
    7. INNER JOIN `operations` AS o ON t.operation=o.id
    8. WHERE
    9. operation>=1000 && operation<2000 GROUP BY cardid
    10. ORDER BY date;
    To copy to clipboard, switch view to plain text mode 

    MAX is safer than COUNT.

    But honestly that's a perfect usecase for triggers - you can have a trigger that will calculate the id itself and modify the query on the fly.

  2. The following user says thank you to wysota for this useful post:

    xgoan (17th March 2008)

Similar Threads

  1. Problems with QSqlQuery update
    By whoops.slo in forum Qt Programming
    Replies: 4
    Last Post: 28th August 2006, 07:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.