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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:23:03+00:00 2026-05-18T00:23:03+00:00

I have a two tables cstomers and orders table. These tables contain 20,000 records

  • 0

I have a two tables cstomers and orders table.
These tables contain 20,000 records

What i need is i want to update the orders table with the customer_id based on the email.
Can i use subquery and php OR it can be accomplished using a single query and efficient method?

customers table

id  email     name
--------------
1 | email1 | name1
2 | email2 | name3
3 | email3 | name3

Orders table

order_id  customer_id   email    product name  group_id
-------------- -----------------------------------------
1         1             email1    prod1          0
2         (NULL)        email1    prod1          1
3         1             email1    prod1          0
4         (NULL)        email2    prod1          1
5         2             email2    prod1          0
6         2             email2    prod1          1
7         (NULL)        email2    prod1          1
2         (NULL)        email1    prod1          1
  • group_id =0 means that the customer has account
  • group_id =1 means that the customer does not have account
  • 1 1 Answer
  • 3 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-18T00:23:04+00:00Added an answer on May 18, 2026 at 12:23 am

    Maybe this (untested)

    UPDATE orders o SET o.customer_id = (SELECT c.customer_id FROM customers c WHERE c.email = o.email)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have two tables, Customers and Orders, and I want to look up
I have two tables Orders table and customers table, both have customerid as common
Customers customer_id Orders order_id customer_id fk If I have two tables and define a
I have two tables. Customers Orders I want to see the latest order for
I have two tables, jos_eimcart_customers_addresses and jos_eimcart_customers. I want to pull all records from
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables that were built for two disparate systems. I have records

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.