#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    PK
    Posts
    57
    Rep Power
    12

    select records from multiple tables


    Following are the two tables

    employee
    --------
    emp_id
    emp_name
    salary

    grade
    ------
    grade
    lowsal
    highsal

    I want to retrieve the grades of each emlpoyee,,, how is it possible,,, what would be the SQL Statements,,,
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    373
    Rep Power
    12
    you need something to join them.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    373
    Rep Power
    12
    so...

    SELECT grades.employee_id, grades.grade, grades.high, grades.low
    FROM employee, grades
    WHERE employee.employee_id = grade.employee_id;

    here you would have had to add the employee_id attribute to grade relation. I forget about if you can use other join syntax in oracle, it's been a while. You can usually do it with NATURAL JOIN in this situation

    SELECT * FROM employee, grades WHERE employee NATURAL JOIN grades;
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,385
    Rep Power
    391
    Code:
    select emp_name,grade 
    from employee , grade
    where salary between lowsal and higsal
    The syntax for a natural join is

    Code:
    SELECT * FROM employee natural join grades
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    12
    Hi zeeshanakhund,

    Which database/version do you use?
    If you use Oracle, the following query will give you the information:
    select * from v$version

    Cheers,
    Dan
    Last edited by Dan Drillich; October 14th, 2003 at 12:17 PM.

IMN logo majestic logo threadwatch logo seochat tools logo