File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Oracle/OAS and the fly likes Need a query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Need a query" Watch "Need a query" New topic
Author

Need a query

Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1558
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

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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

Joined: Jun 22, 2005
Posts: 1558
Thanks Martin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need a query