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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:01:51+00:00 2026-05-21T15:01:51+00:00

I am having some difficulties wrapping my head around this issue. I’m sure there’s

  • 0

I am having some difficulties wrapping my head around this issue. I’m sure there’s a work-around but I’m trying to use a single query. I am joining two tables with a couple of conditions. I need to return all rows matching the ‘t_id’ (even if NULL). I also need to join only the data matching’e_id’. If the ‘e_id’ does not exist, it should return NULL. The following query returns all of the rows that I need:

SELECT b.*, ev.* FROM blocks b 
LEFT OUTER JOIN element_values ev ON ev.b_id = b.id
WHERE t_id = 1;

+----+------+-----------+-----+------+------+-----------------+
| id | t_id | type      | pos | e_id | b_id | value           |
+----+------+-----------+-----+------+------+-----------------+
|  1 |    1 | textinput |   1 |    1 |    1 | this is it edit |
|  2 |    1 | textinput |   0 |    1 |    2 | what is it      |
|  5 |    1 | template  |   2 | NULL | NULL | NULL            |
+----+------+-----------+-----+------+------+-----------------+

But adding another condition for ‘e_id’ will return the accurate data, but will exclude the third row if it is NULL (of course).

SELECT b.*, ev.* FROM blocks b 
LEFT OUTER JOIN element_values ev ON ev.b_id = b.id
WHERE t_id = 1 AND e_id = 1;

+----+------+-----------+-----+------+------+-----------------+
| id | t_id | type      | pos | e_id | b_id | value           |
+----+------+-----------+-----+------+------+-----------------+
|  1 |    1 | textinput |   1 |    1 |    1 | this is it edit |
|  2 |    1 | textinput |   0 |    1 |    2 | what is it      |
+----+------+-----------+-----+------+------+-----------------+

I’m looking for a solution where all three rows are still returned if ‘e_id’ doesn’t exist. For example, with the last query, when I pass ‘e_id = 2’, the set will be empty. But, I need it to still return the all of the rows that equal the ‘t_id’.

Any thoughts are helpful.

Thanks!

  • 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-21T15:01:52+00:00Added an answer on May 21, 2026 at 3:01 pm

    You can inlcude the e_id = 1 in the LEFT JOIN clause to get the rows you want.

    Change your query to as follows:

    SELECT b.*, ev.* 
      FROM blocks b  LEFT OUTER JOIN element_values ev 
        ON ev.b_id = b.id 
       AND e_id = 1
     WHERE t_id = 1; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to C programming and having some difficulties wrapping my brain around
I'm having some difficulties with passing functions around. I have this code: var options
I'm having some difficulties getting my head around Rails' general application layout. Basically, I
I am trying to convert this SQL to linq syntax, but I'm having some
I'm having some difficulties getting the TabActivity to work. Here's the implementation of the
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
Although there are some similar questions I’m having difficulties finding an answer on how
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and
I'm having some difficulties with this problem. The main idea is, I initialized a
I am having some difficulties while trying to understand the radio buttons logic. I

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.