SQL Interview Questions | Common Data

Question

Write a query for collecting the names of children who pursuing their graduation in their residential city.

NAME AGE ADDRESS COLLEGE
……. …… ….. …..

(Hint- Look for the common city name in the columns of ADDRESS and COLLEGE)

Example

Nitin 26 Patna Patna
Ankit 27 Bangalore Pune

Result – Nitin

in progress 3
Dhruv2301 55 years 20 Answers 5900 views Great Grand Master 4

Answers ( 20 )

  1. Select name
    From table
    Where address.city=college.city

  2. Select Name
    From table
    where Address.city = College.city ;

  3. Sorry it a private answer.

  4. /* It will work only if address and College contains the data separated in commas and City name will be at the end*/
    select Name
    from common data
    where Substring_index( address,’,’,-1) =substring_Index (College,’,’,-1)

  5. We need to atleast have some data and assumption for solving this question, Even to have regex we need to see a pattern

  6. select name from table
    where college.city = address.city
    /* work only if there are separate databases for college and address table having city as a column. */

  7. Select distinct Name from table
    Where address = college

    Assuming address and college will have only city names as shown in the example

  8. QUERY:
    SELECT name
    from city
    where city.address=city.college

    TABLE:
    CREATE TABLE IF NOT EXISTS city1 (
    `name` VARCHAR(7) CHARACTER SET utf8,
    `age` INT,
    `address` VARCHAR(9) CHARACTER SET utf8,
    `college` VARCHAR(45) CHARACTER SET utf8
    );
    INSERT INTO city VALUES
    (‘bharath’,21,’khammam’,’khammam’),
    (‘vinni’,20,’bangalore’,’khammam’);

  9. select Name from CommonDate
    where Address = College

  10. SELECT NAME
    FROM table
    WHERE ADDRESS= COLLEGE
    assuming the example as table 1

  11. —Assuming the values in the table are similar to the example given in the question, i.e., the ADDRESS and COLLEGE has only the city names in it.

    SELECT Name
    FROM Table
    WHERE ADDRESS = COLLEGE

  12. SELECT NAME
    FROM SAMPLE
    WHERE ADDRESS= COLLEGE

  13. SELECT NAME
    FROM table
    WHERE ADDRESS= COLLEGE

  14. SELECT
    Name
    FROM
    Table_Name
    WHERE
    Table_Name.address = Table_Name.college;

  15. SELECT name
    FROM table
    WHERE lower(address) = lower(college)

  16. SELECT name FROM table WHERE lower(address) = lower(college)

  17. select name from table
    where lower(address) = lower(college)

  18. SELECT NAME FROM TABLE_NAME WHERE ADDRESS = COLLEGE

  19. SELECT c.name
    FROM table1 as c, table2as a
    where c.address=a.city
    In case there are same tables for address and college use the that in place of one of them

Leave an answer

Browse
Browse