0

Im trying to do Left and Right join but its not working properly . Lemme show you..

Student Table

Student Table

Address Table

Address Table

What's i'm doing?

  1. SELECT * FROM student JOIN address ON student.tid = address.stud_tid

Output:

Simple Join

  1. SELECT * FROM student LEFT JOIN address ON student.tid = address.stud_tid

Output:

Left Join

  1. SELECT * FROM student RIGHT JOIN address ON student.tid = address.stud_tid

Output:

Right Join

May i know why im getting the same out put in every case ?

it should be like rows output like this one

Output Join

Amritesh
  • 87
  • 1
  • 7
  • For every `student.tid` you have a `address.stud_tid` so your joins are all equal. Drop a record from one of those two tables and rerun and you will see different results. – JNevill Dec 12 '19 at 15:34
  • This is a faq. Before considering posting please always google any error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names & site:stackoverflow.com & tags, & read many answers. – philipxy Dec 13 '19 at 03:05
  • Please in code questions give a [mre]--cut & paste & runnable code; example input (as initialization code) with desired & actual output (including verbatim error messages); tags & versions; clear specification & explanation. For errors that includes the least code you can give that is code that you show is OK extended by code that you show is not OK. (Debugging fundamental.) For SQL that includes DBMS & DDL, which includes constraints & indexes & tabular initialization. – philipxy Dec 13 '19 at 03:05

1 Answers1

3

That's because your data are complete. Every student has an address. If you remove one or more addresses, results will be different.

Ykus
  • 65
  • 3