Results 1 to 3 of 3

Thread: How to Extract Particular Records from the Database?

  1. #1
    Join Date
    Jan 2009
    Posts
    41

    How to Extract Particular Records from the Database?

    Hello to all, if I have the following databases:

    IMP (Nimp, Name, Ndipart, Jobs, Director, Stip)
    Departments (Ndipart, NomeDipart, City)
    USO (Ndipart, Part)
    Supply (Supplier, Part)
    And I have the following request:

    List the names and codes in the departments where the average salary of employees is <1000
    What do you think the following solution is correct?

    Select distinct Ndipart, NomeDipart
    from Dept.
    where in Ndipart
    (Select distinct Ndipart
    from imp
    group by Ndipart
    having avg (Stip)> 1000)
    In particular, I want to know:

    1) If you can put in the Select the only attribute of the group by leaving out the one used in having.
    2) When in use where the Strategy "attribute in (new query)" the result of internal query should give only a single attribute comparison outer query? That is, in the Select internal must be only and only the attribute of comparison?

    As always, Thanks.

  2. #2
    Join Date
    Apr 2008
    Posts
    193

    Re: How to Extract Particular Records from the Database?

    What do you think the following solution is correct?

    Select distinct Ndipart, NomeDipart
    from Dept.
    where in Ndipart
    (Select distinct Ndipart
    from imp
    group by Ndipart
    having avg (Stip)> 1000)
    correct, but both are unnecessary DISTINCT.
    The first because not necessarily that you can have separate departments, being the key of the table contained in clause Dept. SELECT The second, because the DISTINCT and implicit in the clause IN (subselects)

    In particular, I want to know:

    1) If you can put in the Select the only attribute of the group by leaving out the one used in having.
    If I understood the question, generally you can make even the GROUP BY clause (and most appropriate frequent), but this situation does not resolve your problem

    2) When in use where the Strategy "attribute in (new query)" the result of internal query should give only a single attribute comparison outer query? That is, in the Select internal must be only and only the attribute of comparison?

    As always, thanks
    Yes, even because it would make no sense and does not serve SELECTION other fields, because the query INNER serve only to search for values to be met for membership clause IN.

    SQL-from Standard and can have only one parameter of comparison group. Some extensions of SQL (Oracle) also include the use of T-uple for this condition,
    ... WHERE (IDDipart, IDNazione) IN (SELECT IDDipart, IDNazione FROM ...)
    useful in this case, for example if the codes of the department are unique only within a nation.

    In SQL-Standard would have had to write a similar flaw,

    ... WHERE (IDNazione * 100000 + IDDipart) IN (SELECT IDNazione * 100000 + IDDipart FROM ...)

  3. #3
    Join Date
    Jan 2009
    Posts
    41

    Re: How to Extract Particular Records from the Database?

    Thanks for answers, All clear.

Similar Threads

  1. How to fetch records from multiple tables in a database ?
    By kALAMATHI in forum Software Development
    Replies: 4
    Last Post: 29-12-2010, 07:56 AM
  2. Creating Database link in database
    By Lachlann in forum Software Development
    Replies: 3
    Last Post: 28-01-2010, 01:17 PM
  3. Possibility to filter the records in a Database
    By Elbanco in forum Software Development
    Replies: 3
    Last Post: 06-11-2009, 09:21 PM
  4. How to Extract records from Mysql database using JTable
    By StudyBoy in forum Software Development
    Replies: 3
    Last Post: 08-04-2009, 06:22 PM
  5. convert filemaker pro database to access database
    By Czack in forum MS Office Support
    Replies: 3
    Last Post: 15-04-2007, 01:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,650,331.43738 seconds with 16 queries