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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:35:35+00:00 2026-05-29T03:35:35+00:00

I am pretty new with SQL and i have to translate this ruby script

  • 0

I am pretty new with SQL and i have to translate this ruby script to SQL because the ruby script is taking WAY too long to run on the server. Here is the ruby script:

orders = Order.find_all_by_state("in_progress"); nil
orders.each do |o|
  if o.line_items.length == 0 and o.created_at > Time.parse("2011-12-14 00:00:00.000000 -08:00") and o.created_at < Time.parse("2011-12-21 00:00:00.000000 -08:00")
    o.adjustments[0].destroy
    o.shipment.destroy
    o.turnaround_time.destroy
    o.checkout.destroy
    o.destroy
  end; nil
end; nil

Anyway, the associations are as follows:

an order has one checkout, shipment, turnaround time, many line_items, and many adjustments (the orders i want to delete only have 1). I want to delete all orders that have no line items and was created within those range of dates (dec 15th-20th). I also want to delete all objects associated with those orders (shipments, turnaround_times, checkouts, adjustments). I am new to SQL and i have absolutely no idea how to do this. I’ve been looking at SQL documentation but i am really struggling with the syntax for this. If i could get some help, that would be great.

  • 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-29T03:35:35+00:00Added an answer on May 29, 2026 at 3:35 am

    To delete orders without any line items:

    delete from order
    where order_id not in (select order_id from line_item);
    

    To delete associated objects that (now) don’t have an order:

    delete from shipment
    where order_id not in (select order_id from order);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty much new to using SQL Server 2000. I have been using
I'm pretty new to SQL. I have a database with records based on road/milepoints.
I am pretty new in SQL so this may be a stupid question... I
I'm working with SQL Server and I'm pretty new to SQL in general, so
I'm pretty new to databases and sql. I have a problem where I have
I am pretty new to both php and SQL. I have a login page
Ok. So I am pretty new a this. I have a datatable that I
I think this should be pretty simple, but I'm a SQL newb. I have
I'm pretty new to SQL, and I'm trying to do something like this: I
I'm pretty new to the idea of recursion and this is actually my first

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.