Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

union join in mysql with example

union join in mysql with example

 
Post new topic   Reply to topic     Forum Index -> DataBase, RDBMS, MySql, Oracle, db2, SQL Server problems
View previous topic :: View next topic  
Author Message
admin
Site Admin


Joined: 24 Aug 2006
Posts: 30

PostPosted: Mon Dec 10, 2007 4:34 pm    Post subject: union join in mysql with example Reply with quote




Union join is very useful when you need to get both record from both table.
Union join in mysql help to fetch records.

Union join combine two tables each other and give result.

Code:

TableA
+---------+------------+
| iCityID | sCityName  |
+---------+------------+
|       3 | Chandigarh |
|       4 | Hissar     |
|       5 | Jabalpur   |
|       6 | jammu      |
+---------+------------+



Code:

TableB
+----------+------------------+
| iStateID | sStateName       |
+----------+------------------+
|        2 | Haryana          |
|        7 | Himachal Pradesh |
|        6 | Jammu & Kashmir  |
|        3 | New Delhi        |
|        5 | Punjab           |
|        8 | Uttar Pradesh    |
|        9 | west bengal      |
+----------+------------------+


Code:

SELECT iStateID, sStateName FROM statemaster s union SELECT iCityID, sCityName FROM citymaster c


Output
Code:
+----------+------------------+
| iStateID | sStateName       |
+----------+------------------+
|        2 | Haryana          |
|        7 | Himachal Pradesh |
|        6 | Jammu & Kashmir  |
|        3 | New Delhi        |
|        5 | Punjab           |
|        8 | Uttar Pradesh    |
|        9 | west bengal      |
|        3 | Chandigarh       |
|        4 | Hissar           |
|        5 | Jabalpur         |
|        6 | jammu            |
+----------+------------------+
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DataBase, RDBMS, MySql, Oracle, db2, SQL Server problems All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack