MySQL LEFT OUTER JOIN

MySQL LEFT OUTER JOIN

Hi There,

I need to perform LEFT OUTER JOIN on 2 tables.

  1. Trans_type tt
  2. Trans t

I used the below MySQL query.

SELECT tt.transtypename, IFNULL(SUM(t.transamt),0) FROM transtype tt LEFT OUTER JOIN trans t ON tt.transtypeid = t.transtypeid WHERE YEAR(t.transcrtndt)='2012' AND MONTH(t.transcrtndt)='1' AND GROUP BY tt.transtypename ORDER BY tt.transtypename

My Requirement

I need all the transtypename from Transtype table and need to find the sum of amount SUM(t.transamt) from trans table even if there is no transaction for that particular trans_type. if there is no transaction either null or 0 should be displayed.

Thanks

View Answers

May 28, 2012 at 4:29 PM

Please visit the following link:

http://www.roseindia.net/sql/sqljoin/mysql-outer-join.shtml

The above link will provide you a good example of Left outer join.

Ads









Related Tutorials/Questions & Answers:
MySQL LEFT OUTER JOIN
MySQL LEFT OUTER JOIN  Hi There, I need to perform LEFT OUTER JOIN... The above link will provide you a good example of Left outer join... OUTER JOIN trans t ON tt.transtypeid = t.transtypeid WHERE YEAR(t.transcrtndt
Hibernate Left Outer Join
In this section, you will learn how to do Left Outer Join in Hibernate
Advertisements
Mysql Outer Join
Mysql Outer Join       Mysql Outer Join return you the set of all matching records from both... in set (0.00 sec) Left Outer Join:- Query to join the data
Mysql Left Join
Mysql Left Join       Mysql Left Join return you the set of records of right table matches... illustrate an example from Mysql Left Join. To understand this example, we create
Mysql Full Join
; Mysql Full Join is used to return all the records from both left... is the outcome result set of left outer join and right outer join using UNION... * from Roseindia as R -> left outer join newstrack as N ->
Hibernate Right Outer Join
In this section, you will learn how to do Right Outer Join in Hibernate
SQL LEFT JOIN
SQL LEFT JOIN       The LEFT JOIN keyword retrieve all rows from the left table (table_name1... with Example The Tutorial illustrate an example from SQL LEFT JOIN
Mysql Join 3 Tables
Mysql Join 3 Tables       Mysql Join 3 Tables is used to join 3 Tables using left join... an example from 'Mysql Join 3 Tables' using Left Join. To grasp this example
PHP SQL Left Join
PHP SQL Left Join  This Example illustrates how to use left join clause in the sql query. The left join return all rows from the left table, even if there are no matches in the right table. In this example left join is used
Natural Left Join
the MySql database. To join the table in a natural left join manner... Natural Left Join      ... will be natural left join.  To join the tables firstly it is important to make
PHP SQL Left Join
PHP SQL Left Join       This Example illustrates how to use left join clause in the sql query.  JOIN is used to query data from two or more tables. The left join
Join tables with the NATURAL LEFT JOIN operation
Join tables with the NATURAL LEFT JOIN operation       This section describes the NATURAL LEFT JOIN... the help of NATURAL LEFT JOIN operation. It retrieves data on the specific field
SQL LEFT JOIN
SQL LEFT JOIN       The LEFT JOIN keyword retrieve all rows from the left table (table_name1... with Example The Tutorial illustrate an example from SQL LEFT JOIN
Mysql Left
Mysql Left       Mysql Left is used to return the Left String character from a String. Understand with Example The Tutorial illustrate an example from 'Mysql Left
SQL Join
the records from both left and right outer join. The joined table contain all records... in the joined table.   Mysql Left Join return you the set... Tables Mysql Join 3 Tables is used to join 3 Tables using left join
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output    I have three...(i.InvoiceQuantity),sum(p.IssueQuantity) from Stock s left join InwardEntry i on s.partno=i.partno left join IssueToProd p on s.partno=p.partno group by s.partno
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output    I have three...(i.InvoiceQuantity),sum(p.IssueQuantity) from Stock s left join InwardEntry i on s.partno=i.partno left join IssueToProd p on s.partno=p.partno group by s.partno
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output    I have three...(i.InvoiceQuantity),sum(p.IssueQuantity) from Stock s left join InwardEntry i on s.partno=i.partno left join IssueToProd p on s.partno=p.partno group by s.partno
SQL Right JOIN
RIGHT OUTER JOIN. In this example, The table Stu_Table and Lib_Table... RIGHT OUTER JOIN is given below: SELECT column_name... use RIGHT OUTER JOIN, which displays the records from two tables
Mysql Left
Mysql Left       Mysql Left is used to return the left string from the character... illustrate an example from 'Mysql Left'.To understand the example we create
Hibernate Outer Join
In this section, you will learn about types of outer joins in Hibernate
Mysql Join
Mysql Join       Mysql Join is used to join the records from two table using join clause... 'Join in Mysql'. To grasp this example, we create a table roseindia with required
Mysql Left Function
Mysql Left Function       Mysql Left Function is used to return the leftmost string... to learn an example from 'Mysql Left Function'.To understand  this example,we
Mysql Left Function
Mysql Left Function       Mysql Left Function is used to return the leftmost string character from... from 'Mysql Left Function'. To understand  this example, we simply create
Mysql Join Types
and newstrack using left outer join:- The below Query return you the set of records... Mysql Join Types      ... | +-------+-----------+------------------+ 3 rows in set (0.02 sec) OUTER JOIN
Mysql Natural Join
Mysql Natural Join       Mysql Natural Join is a specialization of equi-joins. The join... The Tutorial illustrate an example from 'Mysql Natural Join'. To grasp this example, we
Mysql Join Query
Mysql Join Query       Mysql Join Query is used to return the matchable records from ... The Tutorial illustrate an example from Mysql Join Query. To grasp this we create a table
Mysql Cross Join Statement
Mysql Cross Join Statement       Mysql Cross Join Statement is used to return the product... illustrate an example from 'Mysql Cross Join Statement '. To understand
Mysql Inner Join
Mysql Inner Join       Mysql Inner Join returns the set of  only those records which... illustrate an example from 'Mysql Inner Join'. To grasp this example we create
Java Cross Join MySQL
Java Cross Join MySQL In this section we will read about how the two tables can be joined using cross join in MySQL. Here we will see cross joining using... cross join in Java using MySQL. In this example we will first create two
Mysql Cross Join
Mysql Cross Join      ... to represent Cross Join in Mysql :          ... in Mysql. To understand cross join, we create a table rose india with required

Ads