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
SQL
55 years
20 Answers
5863 views
Great Grand Master 4
Answers ( 20 )
Select name
From table
Where address.city=college.city
Select Name
From table
where Address.city = College.city ;
Sorry it a private answer.
/* 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)
We need to atleast have some data and assumption for solving this question, Even to have regex we need to see a pattern
Done
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. */
Select distinct Name from table
Where address = college
Assuming address and college will have only city names as shown in the example
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’);
select Name from CommonDate
where Address = College
SELECT NAME
FROM table
WHERE ADDRESS= COLLEGE
assuming the example as table 1
—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
SELECT NAME
FROM SAMPLE
WHERE ADDRESS= COLLEGE
SELECT NAME
FROM table
WHERE ADDRESS= COLLEGE
SELECT
Name
FROM
Table_Name
WHERE
Table_Name.address = Table_Name.college;
SELECT name
FROM table
WHERE lower(address) = lower(college)
SELECT name FROM table WHERE lower(address) = lower(college)
select name from table
where lower(address) = lower(college)
SELECT NAME FROM TABLE_NAME WHERE ADDRESS = COLLEGE
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