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

  • Home
  • SEARCH
  • 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 4061954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:32:14+00:00 2026-05-20T15:32:14+00:00

Two tables: table1 id | name 1 | aaa 2 | bbb 3 |

  • 0

Two tables:

table1  
id | name
1  | aaa
2  | bbb
3  | ccc

table2
id | param
1  | x
1  | z
2  | x

table1.id = table2.id

I need to select everything from table1, with field param (1 if have, 0 if no, or null) by given param.

For example, by param “x”:

result:
id | name | param
1  | aaa  | 1
2  | bbb  | 1
3  | ccc  | 0

All I can do is just:

SELECT table1.id, table1.name, table2.param
FROM table1 
LEFT JOIN table2 ON table1.id = table2.id
WHERE table2.param = 'x'

But it doesn’t select all table1.
What is the right query for this task?

  • 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-20T15:32:15+00:00Added an answer on May 20, 2026 at 3:32 pm

    You are applying the filter AFTER the join. Try this instead:

    SELECT table1.id, table1.name, table2.param
    FROM table1 
    LEFT JOIN table2 ON table1.id = table2.id and table2.param='x'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables table1: { id, name } table2: { id, table1_id, time_added
There are two tables table1 and table2 table1 has got two columns name and
i have two different tables table1 - property ================= id,name, address, city state, zip
sqlite3 I have two tables, Table1 and Table2. Both of these tables have a
I have two tables that have following rows: Table1 ID Name Number ===================== 1
I have two tables which have the exact same structure. Both tables can store
I have two tables: Table 1 id app_name app_id 1 name1 12001 2 name2
Is there a way to join multiple row lines a single one using two
I wonder if someone can help me translate a MySQL query to a (Db)LINQ
Without actually giving all the details of my query: Is there a way of

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.