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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:58:46+00:00 2026-05-28T06:58:46+00:00

I have two tables: CATALOG: ———————————— | itemID | itemCode | itemName | ————————————

  • 0

I have two tables:

CATALOG:
------------------------------------
| itemID    | itemCode  | itemName |
------------------------------------

ORDER:
----------------------------------------------
| orderID   | itemID_FK | itemPrice | etc... |
----------------------------------------------

I want to select itemName, itemPrice, itemCode etc by using a join on both tables.

So far so good; however, the row corresponding to a given itemID in CATALOG may not exist in the ORDER table. In which case, I want to fall back on using itemName, itemCode from the first table CATALOG.

Is this possible using MYSQL in a single (compound) statement?

EDIT:
Here’s a sample table

CATALOG:
------------------------------------
| itemID    | itemCode  | itemName |
------------------------------------
|  1        |  89873232 | Oats     |
|  2        |  32849392 | Beer     |
------------------------------------

ORDER:
----------------------------------------------
| orderID   | itemID_FK | itemPrice | etc... |
----------------------------------------------
| 213232    |  2        |  3.99     |  ...   |
----------------------------------------------

I use the following query to retrieve complete data about an item:

SELECT itemID, itemName, itemPrice FROM CATALOG
INNER JOIN ORDER
ON itemID = itemID_FK
WHERE itemID = %d

I need this join because CATALOG will not contain price which is obtained from ORDER. If I use itemID=1 there would not be a corresponding entry in ORDER table and the query would fail. I want it to retrieve at least itemName if there is no entry for the item in ORDER

  • 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-28T06:58:47+00:00Added an answer on May 28, 2026 at 6:58 am

    Just use a LEFT OUTER JOIN between the two tables, so you will always have data corresponding to the table on the LEFT side of the JOIN:

    SELECT C.itemName, C.itemCode, O.itemPrice, ...
    FROM CATALOG as C
         LEFT OUTER JOIN ORDER AS O ON C.itemID = O.itemID_FK
    

    All the O.s in the above selection will turn up as NULL if the item from the CATALOG does not exist in ORDERS.

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

Sidebar

Related Questions

I have two tables Order , OrderStatus . Order has OrderId (pk), OrderStatusId (fk)
I have two tables containing Tasks and Notes, and want to retrieve a list
I have two tables rooms and users . I want to get only rooms.room_id
I have two tables and want to compare rows on sqlite like this table1
I have two tables in my MySQL database (table1 and table 2). I want
Have two tables named Employee and Order. The relations between the tables Employee (1)
I have two tables that I want to use for viewing my reports which
I have two tables: Projects and ProjectsData and I want to execute query with
I have two tables in MySql Company : (cname,city) works : (ename,cname,salary) I want
I have two tables. I want them be near each other and not like

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.