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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:22:19+00:00 2026-05-20T05:22:19+00:00

I have the sql query below. I want to take the results and insert

  • 0

I have the sql query below. I want to take the results and insert it into another table using the insert below. Is this a good choice for a stored procedure.

It doesn’t need to run very often, so no need to attach it to a trigger… I’ll probably just write a php script to trigger it via an hourly cron job. (or maybe I can trigger it via command line)

So, am I barking up the wrong tree on this one? Thanks Oh, I’ll accept any helpful answer.

 SELECT
  COUNT(*) AS thecount,
  MAX(datetime_acc) AS DATE,
  u.created_usr,
  @payout:=IF(u.created_usr < '2011-01-24',20,10) AS payout,
  level_usr,
  @uid_usr:=p.uid_usr,
  @affiliate:=u.affiliate_aff,
  created_usr,
  firstname_usr, 
  lastname_usr,
  contact_aff,
  c.id_com

FROM payment_acc p
 LEFT JOIN users_usr u ON p.uid_usr = u.id_usr 
 LEFT JOIN commissions_com c ON c.uid_usr = u.id_usr
 LEFT JOIN affiliate_aff a ON a.code_aff = u.affiliate_aff




WHERE p.type_acc = 'monthly payment'
AND affiliate_aff IS NOT NULL
GROUP BY p.uid_usr
HAVING thecount > 1

ORDER BY affiliate_aff

The INSERT:

Insert into commissions_com 
    date_generated_com,
    amount_com,
    uid_usr, 
    code_aff, 
    status_com
values
   (NOW(),
    @payout,
    @uid_usr,
    @code_aff,
    'new')
  • 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-20T05:22:20+00:00Added an answer on May 20, 2026 at 5:22 am

    What “value” are you looking for?

    Jeff Atwood has for a long time questioned the use for stored procuedres.

    From the mysql documentation:

    MySQL 5.0 introduced Stored Procedures
    which allow us to automate or program
    our way out of many tasks on directly
    on the server rather than having to
    write external scripts to do complex
    manipulation of data.

    As you get used to writing stored
    Procedures in MySQL 5.0, you will, as
    with any other programming language,
    want to generalize your stored
    procedures as much as possible. The
    more flexible your stored procedure
    is, the more tasks it can be used for
    — and the less places you have to go searching for that elusive bug that
    just keeps giving you the wrong
    result. The day you end up making a
    copy of a stored procedure just to
    change a name or two is the day you
    need to think how tweaking the
    original procedure can accomplish what
    you want without breaking old
    functionality.

    From what you have described, your script doesn’t sound general or to be used for several tasks.

    For the time being then, I would avoid a stored procedure.

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

Sidebar

Related Questions

I have the below sql query to insert the records from a table. The
I have a SQL query where I want to insert multiple rows in single
I have a sql query shown below i want to use the variables streetname,
I have given the required table and resultant table below. Give query for SQL
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
Can we have a SQL query which will basically help in viewing table and
This might be a very simple thing. Check out the normal sql query below
I have SQL query, which is working nice on Oracle and MSSQL. Now I'm
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have a SQL query (MS Access) and I need to add two columns,

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.