Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2015
    Posts
    6

    Unanswered: Help with subquery

    Hello, i am new to SQL and starting to learn T-SQL commands.

    I have got a table named world ( countryname,continent,GDP, and area columns) and i am trying to Show the countries in Europe with a GDP greater than 'United Kingdom'. Any help would be greatly appreciate. Thx luka1966

  2. #2
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    Instead of learning T-SQL commands let's stick with ANSI - SQL, that way we aren't stuck with SQL server, oracle or some other RDBMS, we can query on any of them.

    The typical query goes along the lines of:
    Code:
    SELECT SOME_COLUMN(s)
        FROM SOME_TABLE(s)
    WHERE A_COLUMN = THIS_OR_THAT_CONDITION
      AND .......
    you have an additional requirement that can be handled in a multitude of ways. You could just inner join to another representation of your same table. You could add an EXISTS or > with a subquery to another representation of your table. Such as:
    Code:
    SELECT SOME_COLUMNS
        FROM SOME_TABLE A
    INNER JOIN SOME_TABLE B
          ON B.COUNTRY = ?
       AND A.COLUMN > B.COLUMN
    WHERE A_COLUMN = THIS_OR_THAT_CONDITION
      AND .......
    Code:
    SELECT SOME_COLUMNS
        FROM SOME_TABLE A
    WHERE A_COLUMN = THIS_OR_THAT_CONDITION
      AND EXISTS (SELECT 1 FROM SOME_TABLE B
                          WHERE A.COLUMN > B.COLUMN
                               AND B.COUNTRY = ?)
      AND .......
    Code:
    SELECT SOME_COLUMNS
        FROM SOME_TABLE A
    WHERE A_COLUMN = THIS_OR_THAT_CONDITION
      AND A.COLUMN > (SELECT B.COLUMN FROM SOME_TABLE B
                          WHERE  B.COUNTRY = ?)
      AND .......
    Dave

  3. #3
    Join Date
    Feb 2015
    Posts
    6

    Help with subquery

    Thank you Dave.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •