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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:34:40+00:00 2026-05-24T03:34:40+00:00

I’ve created the following SQL query to export order data from the database. SELECT

  • 0

I’ve created the following SQL query to export order data from the database.

SELECT orders.orders_id as uuid,
        orders.customers_id as order__customer_id,
        orders.customers_name as order__customer_name,
        orders.customers_company as order__customer_company,
        orders.customers_street_address as order__customer_street_address,
        orders.customers_suburb as order__customer_suburb,
        orders.customers_city as order__customer_city,
        orders.customers_postcode as order__customer_postcode,
        orders.customers_state as order__customer_state,
        orders.customers_country as order__customer_country,
        orders.customers_telephone as order__customer_telephone,
        orders.customers_email_address as order__customer_email_address,
        orders.delivery_name as order__delivery_name,
        orders.delivery_company as order__delivery_company,
        orders.delivery_street_address as order__delivery_street_address,
        orders.delivery_suburb as order__delivery_suburb,
        orders.delivery_city as order__delivery_city,
        orders.delivery_postcode as order__delivery_postcode,
        orders.delivery_state as order__delivery_state,
        orders.delivery_country as order__delivery_country,
        orders.billing_name as order__billing_name,
        orders.billing_company as order__billing_company,
        orders.billing_street_address as order__billing_street_address,
        orders.billing_suburb as order__billing_suburb,
        orders.billing_city as order__billing_city,
        orders.billing_postcode as order__billing_postcode,
        orders.billing_state as order__billing_state,
        orders.billing_country as order__billing_country,
        orders.payment_method as order__payment_method,
        orders.last_modified as order__last_modified,
        orders.date_purchased as order__date_purchased,
        orders.orders_status as order__order_status,
        orders_status.orders_status_name as order__order_status_name,
        orders.orders_date_finished as order__date_finished,
        orders.currency as order__currency,
        orders.currency_value as order__currency_value,
        ot1.orders_id,
        value AS ot_subtotal,
        ot2.ot_shipping,
        ot3.ot_total
        FROM orders, orders_status, orders_total as ot1 
        INNER JOIN ( SELECT orders_id, value AS ot_shipping FROM orders_total WHERE class='ot_shipping' ) AS ot2 ON ot1.orders_id=ot2.orders_id AND ot1.class='ot_subtotal' 
        INNER JOIN ( SELECT orders_id, value AS ot_total FROM orders_total WHERE class='ot_total' ) AS ot3 ON ot1.orders_id=ot3.orders_id AND ot1.class='ot_subtotal'
        WHERE ot1.orders_id = ot2.orders_id and orders.orders_status = orders_status.orders_status_id;

It works fantastic, except it’s creating 4 rows for every record. Currently there are 4 orders, so there are 16 rows (17 including the column names), when there should only be 4 (5 including the column names).

Thanks!

When it should only be 4 rows (5 including the column names) as there are only 4 orders.

Much appreciated!

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

    Try using SELECT DISTINCT in your query.

    SELECT DISTINCT orders.orders_id as uuid...
    FROM orders, orders_status, orders_total as ot1 
    INNER JOIN ( SELECT orders_id, value AS ot_shipping FROM orders_total WHERE class='ot_shipping' ) AS ot2 ON ot1.orders_id=ot2.orders_id AND ot1.class='ot_subtotal' 
    INNER JOIN ( SELECT orders_id, value AS ot_total FROM orders_total WHERE class='ot_total' ) AS ot3 ON ot1.orders_id=ot3.orders_id AND ot1.class='ot_subtotal'
    WHERE ot1.orders_id = ot2.orders_id and orders.orders_status = orders_status.orders_status_id;
    

    EDIT:

    I updated your FROM portion to the below using INNER JOINs on all of the tables instead of ‘,’. I don’t know your table structures so I am guessing on your join fields.

    FROM orders
    INNER JOIN orders_status
        ON orders.orders_status = orders_status.orders_status_id
    INNER JOIN orders_total as ot1 
        ON orders.orders_id = ot1.orders_id
    INNER JOIN ( SELECT orders_id, value AS ot_shipping FROM orders_total WHERE class='ot_shipping' ) AS ot2 
        ON ot1.orders_id=ot2.orders_id 
    INNER JOIN ( SELECT orders_id, value AS ot_total FROM orders_total WHERE class='ot_total' ) AS ot3 
        ON ot1.orders_id=ot3.orders_id
    WHERE ot1.class='ot_subtotal'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in

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.