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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:30:05+00:00 2026-05-26T23:30:05+00:00

MySQL Tables MySQL: Plants +—-+——–+ | id | plant | +—-+——–+ | 1 |

  • 0

MySQL Tables

MySQL: Plants

+----+--------+
| id | plant  |
+----+--------+
| 1  | tree   |
+----+--------+
| 2  | flower |
+----+--------+
| 3  | tree   |
+----+--------+

MySQL: Trees

+----+------+
| id | type |
+----+------+
| 1  | hard |
+----+------+
| 3  | soft |
+----+------+

What I’m trying to do

I want to select all rows in the table plants.

But if plant = tree, then the type in the table trees must be hard in order for it to be displayed.

So, the example above should output: 1=tree and 2=flower.

3=tree should be excluded because its type = soft.

What I’ve tried so far…but didn’t work

a) I guess I cannot use union, because the columns are different.

b) I already tried left join, but that didn’t work either:

select p.id, p.plant
from plants AS p
left join
(
   select `id`, `type`
   from `trees`
) AS t ON p.id = t.id
WHERE t.type = 'hard'

any ideas on how I can do it?

  • 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-26T23:30:06+00:00Added an answer on May 26, 2026 at 11:30 pm

    yes

    select p.id, p.plant from plants as p left join trees as t on (p.id = t.id) where t.type = 'hard' or t.type is null
    

    I hope this works. Anyway the problem with your current query is not the left join (that is ok actually), but that you specify the tree type must be hard so you eliminate the rows with null tree that the left join gave you.

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

Sidebar

Related Questions

I have this mysql tables I want to display with jqgrid. The problem appears
I have two MySQL tables, and I want to find and replace text strings
I have two mysql tables and i want to merge the results of these
I have 2 large mysql tables: Articles and ArticleTopics. I want to query the
I have two mysql tables - a sales table: +----------------+------------------------------+------+-----+---------+-------+ | Field | Type
I have two MySQL tables. What I am trying to do is to export
I have 2 mysql tables and I want that: 1) when I delete an
I am dealing with MySQL tables that are essentially results of raytracing simulations on
I have two mysql tables, one containing details on cars and one containing all
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever

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.