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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:10:58+00:00 2026-06-01T23:10:58+00:00

I need to select and update a table looking up values from other tables.

  • 0

I need to select and update a table looking up values from other tables. The idea is to select some details from order, but get the names of the foreign key values using the id

For the select I tried:

SELECT [Order].order_date, 
       [Order].total_price, 
       [Order].order_details,
       vehicle.reg_no,
       Staff.name,
       stock.name 
FROM 
       Order,
       vehicle,
       staff,
       stock
WHERE
      order.id = @order_id 
  AND vehicle.id = Order.vehicle_id 
  AND staff.id = Order.staff_id 
  AND stock.id = Order.product_id

for the update that i tried

UPDATE order 
SET 
    total_price = @total_price, 
    order_detail = @order_detail,
    product_id = (select is from stock where name = @product_name), 
    customer_id = (select id  from customer where name = @customer_name), 
    vehicle_regno = (select reg_no  from vehicle where name = @name)
WHERE (id = @id)

both does not return anything. i hope am clear enough to get some help, but if not pls i will provide more info.

thanks for helping

  • 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-06-01T23:11:00+00:00Added an answer on June 1, 2026 at 11:11 pm

    You might want to try converting you INNER JOINs to a LEFT JOIN for the SELECT statement.

    SELECT [Order].order_date, 
           [Order].total_price, 
           [Order].order_details,
           vehicle.reg_no,
           Staff.name,
           stock.name 
    FROM 
           [Order] 
           LEFT JOIN vehicle
           ON vehicle.id = [Order].vehicle_id 
           LEFT JOIN staff
           ON staff.id = [Order].staff_id
           LEFT JOIN stock
           ON stock.id = [Order].product_id
    WHERE
          [order].id = @order_id 
    

    The reasons why this would make a difference is if either a) you allow nulls in the fk fields or b) you don’t have fk contraints which may point to a problem with your design.

    Your update statement should update some rows provided that the value of @id exists in the ORDER table but as @Danny Varod already commented you won’t get rows back only the number of rows affected

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

Sidebar

Related Questions

I need to select all columns from two tables, but need to be able
I need to select multiple records I use SELECT * FROM `table` WHERE `ID`
I need to select data from one table and insert it into another table.
I need to select rows randomly from an Oracle DB. Ex: Assume a table
I need to select a field called ProgramID from a table and if the
I need to update select occurrences in different tables of the [ISD_ID] attribute, how
I need to select 5 most recent rows from cached Dataview object, is there
I need to select multiple table and one of it is transposed, my table
I have the table: select * from person; +----+------+---------+ | id | name |
I need to list (and later update) all the items present in the table

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.