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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:50:50+00:00 2026-06-02T17:50:50+00:00

**TableFruits** **TableNames** RecId RId FruitId Price RId FruitId Name 1 A1 Null 3$ A1

  • 0
      **TableFruits**                        **TableNames**
   RecId    RId      FruitId       Price         RId  FruitId       Name
     1      A1        Null           3$           A1      1        Mango
     2      A2         2             4$           A2      2       Tomato

Since there is Null under FruitId in TableFruits I want to fetch it from TableNames like

Select a.RecId,a.RId,b.FruitId from TableFruits a INNER JOIN TableNames b on a.RId=b.RId 
  1. How do I apply a join in this SQL statement to include FruitNames from Table 2 (I cannot change the order of tables)
  • 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-02T17:50:53+00:00Added an answer on June 2, 2026 at 5:50 pm
    SELECT a.RecId
         , a.RId
         , COALESCE(a.FruitId, b.FruitId) AS FruitId
         , b.Name
    FROM TableFruits a 
      JOIN TableNames b 
        ON b.RId = a.RId  ;
    

    Since you can have mismatches in RId, you need an outer join. LEFT, RIGHT or FULL, depending on which side the mismatches can occur.

    MySQL does not have FULL JOIN, so you can do something like this:

    SELECT a.RecId
         , a.RId
         , COALESCE(a.FruitId, b.FruitId) AS FruitId
         , b.Name
    FROM TableFruits a 
      LEFT JOIN TableNames b 
        ON b.RId = a.RId 
    
    UNION ALL
    
    SELECT NULL
         , NULL
         , b.FruitId
         , b.Name
    FROM TableFruits a 
      RIGHT JOIN TableNames b 
        ON b.RId = a.RId 
    WHERE a.RId IS NULL  ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write an efficient query which returns a list of fruits by
I have a table (Fruits) with following column Fruit_Name(varchar2(10)) | IsDuplicate Number(1) Mango 0
I want to do the following in PostgreSQL (using Hibernate): ALTER TABLE fruits ADD
I had 2 tables: fruits and vegetables fruits is as follow: id - name
I have a table Fruits that contains the following columns UserID | FruitID I
I have the following Db and query. The query takes two parameters: the sort
I have a table fruits with the following data id a 123 apple 223
In SQL Server 2008 I have a Table- Fruits Items Orders Bananas 6 Bananas
Why it stops to work on second $mysqli->prepare($query) statement? $mysqli = @new mysqli(HOSTNAME, USERNAME,
I have implemented a db which is consisted of Article and Fruit tables, with

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.