• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Need a query

 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Martin.
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic