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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:10:36+00:00 2026-06-18T00:10:36+00:00

I got two mysql table like this CREATE TABLE IF NOT EXISTS tbl1 (

  • 0

I got two mysql table like this

CREATE  TABLE IF NOT EXISTS tbl1 (
`id` INTEGER(2) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT ,
`name` VARCHAR(20) NOT NULL
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE  TABLE IF NOT EXISTS tbl2 (
`tbl_id` INTEGER(2) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT ,
`id2` INTEGER(2) UNSIGNED NOT NULL ,
`email` VARCHAR(20) NOT NULL ,
FOREIGN KEY (`id2`) REFERENCES tbl1(`id`)
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;

Here is example data in tbl1

1   hello
2   world
3   happy
4   end

and example data in tbl2

2   1   me@mail
3   2   my@mail
4   4   you@mail

now I want to select name and email joining two table. Here is the sql

select name,email from tbl1 t1,tbl2 t2 where t2.id2 = t1.id;

with it i’m getting

hello   me@mail
world   my@mail
end     you@mail

but I want all row from tbl1

hello   me@mail
world   my@mail
happy   null or nothing or 0
end     you@mail

here i am stuck. any help will be appreciated.
thanks in advance.

  • 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-18T00:10:37+00:00Added an answer on June 18, 2026 at 12:10 am

    You should use a LEFT JOIN:

    select name,email 
    from tbl1 t1
    LEFT JOIN tbl2 t2 
      on t1.id = t2.id2;
    

    See SQL Fiddle with Demo.

    Your current query is using an INNER JOIN which will only return the rows that are matching in both tables. The LEFT JOIN will return all records in tbl1 even if there is no matching row in tbl2.

    If you need help learning join syntax here is a visual explanation of joins

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

Sidebar

Related Questions

Hi i ve got two tables like this: mysql> describe tb_data_iae; +--------------------+--------------+------+-----+---------+----------------+ | Field
empty (not null!)I want to create sql statement as this: SELECT * FROM table
I want to create a table with Primary key referenced to Two columns of
I've got a MySQL table with, among other things, two fields: a (int) and
So, I've got a mysql query that looks like this: SELECT rewards.name, redemptions.points, redemptions.value
I have a MySQL database with two tables (simplified for this question): movies table
I've got two data tables like below. Table 1: -------------------- sbstart sbend totsb --------------------
I got two tables in my database: user and call. User exists of 3
I have a mysql table like: Sample Data ID STUDENT_ID Branch_id Class_id Exam_id Subject_id
I have two databases, one MySQL 5, one SQL Server 2000. I've got the

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.