File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need a query

 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have following tables Table1 with only one column UIDand table2 with UserID, and some more columns

Table1
-----------------------
UID
-----------------------
records...


Table2
----------------------------------------------
UserID | Detail1 | Detail2
----------------------------------------------
records...



Table1 is my input and I want to read records one by one from table1 (UID) and search them in table2(UserID) if there is a match i have to display all the details (UserID, details1 and detail2) from table2.

Will a Join work on this? Is myy following SQL right ?




For example

EMP
---------
UserID
---------
101
102
103

EMP2
---------------------------
EmpID | Name | Sal
---------------------------
100 John 1000
101 Alex 2000
102 Peter 3000
103 Stella 4000
104 Mary 5000


I want my output to be
EmpID | Name | Sal
101 Alex 2000
102 Peter 3000
103 Stella 4000
 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this query would produce the result in your example (have you tried?)

The query is an inner join. If there is a row in Table1 without matching row in Table2, such a row won't appear in the output. If you would want to include such rows from Table1 in the query, you'd need to use an outer join.

I'd also suggest using ANSI syntax for joins. It works the same as Oracle's syntax, but is perhaps easier to read (especially in case of outer joins) and is portable to other databases, so it makes more sense to learn using it. If you're unsure about joins in SQL, I'd suggest trying to find an SQL tutorial.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Martin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic