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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:57:42+00:00 2026-05-10T21:57:42+00:00

Simplified for example, I have two tables, groups and items . items ( id,

  • 0

Simplified for example, I have two tables, groups and items.

items (     id,     groupId,     title )  groups (     id,     groupTitle,     externalURL ) 

The regular query I’m goes something like this:

SELECT     i.`id`,     i.`title`,     g.`id` as 'groupId',     g.`groupTitle`,     g.`externalURL` FROM     items i INNER JOIN groups g ON (i.`groupId` = g.`id`) 

However I need to modify this now, because all the groups which specify an externalURL will not have any corresponding records in the items table (since they’re stored externally). Is it possible to do some sort of join so that the output looks kinda like this:

items: id    title    groupId ---------------------- 1     Item 1   1 2     Item 2   1  groups id    groupTitle    externalURL ------------------------------- 1     Group 1       NULL 2     Group 2       something 3     Group 3       NULL  Query output: id    title    groupId    groupTitle    externalURL --------------------------------------------------- 1     Item 1   1          Group 1       NULL 2     Item 2   1          Group 1       NULL NULL  NULL     2          Group 2       something  -- note that group 3 didn't show up because it had no items OR externalURL 

Is that possible in one SQL query?

  • 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. 2026-05-10T21:57:42+00:00Added an answer on May 10, 2026 at 9:57 pm

    This is exactly what an outer join is for: return all the rows from one table, whether or not there is a matching row in the other table. In those cases, return NULL for all the columns of the other table.

    The other condition you can take care of in the WHERE clause.

    SELECT     i.`id`,     i.`title`,     g.`id` as 'groupId',     g.`groupTitle`,     g.`externalURL` FROM     items i RIGHT OUTER JOIN groups g ON (i.`groupId` = g.`id`) WHERE i.`id` IS NOT NULL OR g.`externalURL` IS NOT NULL; 

    Only if both i.id and g.externalURL are NULL, then the whole row of the joined result set should be excluded.

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

Sidebar

Ask A Question

Stats

  • Questions 109k
  • Answers 109k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The JVCL plugin manager works just fine, but if you… May 11, 2026 at 9:25 pm
  • Editorial Team
    Editorial Team added an answer I haven't done this before but from reading your description… May 11, 2026 at 9:25 pm
  • Editorial Team
    Editorial Team added an answer Here is an actual example that I put together that… May 11, 2026 at 9:25 pm

Related Questions

I ran into a scenario where LINQ to SQL acts very strangely. I would
I am using the operator overloading for records in Delphi 2006. (Please don't answer
I have a string which has several html comments in it. I need to
I am putting an XSL together than will create a NAnt build script using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.