Test Your Knowledge: 25 SQL Subquery Questions

HOME




SELECT employee_id FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
   




SELECT * FROM employees WHERE department_id = (SELECT department_id FROM departments WHERE name = 'Sales');



a) SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
b) SELECT * FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id);
c) SELECT * FROM employees WHERE salary IN (SELECT salary FROM employees);
d) SELECT * FROM employees WHERE id IN (SELECT id FROM departments);



SELECT * FROM employees 
   WHERE salary BETWEEN (SELECT max(salary) FROM employees WHERE department_id = 100) AND 
  (SELECT min(salary) FROM employees WHERE department_id = 100);

SELECT department_id FROM departments WHERE department_id = (SELECT MAX(department_id) FROM departments);

a)  UPDATE employees SET salary = salary * 1.1 WHERE department_id = (SELECT department_id FROM departments);
b)	 UPDATE employees SET salary = salary * 1.1 WHERE department_id = (SELECT department_id FROM departments WHERE name = 'HR');
c)  UPDATE employees USING (SELECT department_id FROM departments WHERE name = 'HR');
d)  UPDATE employees SET salary = 1.1 * (SELECT salary FROM employees);

DELETE FROM employees WHERE manager_id IN (SELECT employee_id FROM employees WHERE department_id = 3);

SELECT first_name, last_name, salary FROM employees WHERE salary ANY 
(SELECT salary FROM employees);


a) SELECT * FROM (SELECT column1 FROM table1) AS subquery;
b) SELECT * FROM table1 WHERE column1 = (SELECT column2 FROM table2);
c) SELECT * FROM table1 INNER JOIN (SELECT column2 FROM table2) AS subquery;
d) SELECT column1 FROM table1 WHERE column2 = (SELECT column2 FROM table2) AND column3 = (SELECT column3 FROM table3);

SELECT first_name, last_name FROM employees WHERE emp_id  NOT IN 
(SELECT manager_id, hire_date FROM employees WHERE manager_id IS NOT NULL);





SQL Multiple Choice Questions & Answers – JOINS

HOME


SELECT products.product_name, orders.order_date
FROM products
INNER JOIN orders ON products.product_id = orders.product_id;


SELECT students.student_name, grades.grade
FROM students
__________ JOIN grades ON students.student_id = grades.student_id;
   


SELECT a.name, b.address
FROM customers a
FULL OUTER JOIN orders b ON a.customer_id = b.customer_id;


SELECT e.employee_id, e.name, d.department_name
FROM employees e
CROSS JOIN departments d;











What will be the result of inner join between these tables?



a) Select * FROM Table1 T1 CROSS JOIN Table1 T2;
b) Select * FROM Table1 T1 ALL CROSS JOIN Table1 T2;
c) Select * FROM Table1 T1,Table1 T2;
d) Select * FROM Table1 T1 CROSS Table1 T2;



SELECT * FROM students NATURAL JOIN enrollments;

SpringBoot – Multiple Choice Questions and Answers – MCQ2

HOME


@ConfigurationProperties(prefix = "app")
public class AppConfig {
      private String name;
      private String version;
     // Getters and setters
}


@Service
public class ArticleService {
    @Autowired
    private ArticleRepository articleRepository;
}


@RestController
public class MyController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello, World!";
    }
}
@Controller
@RequestMapping("/api")
public class MyController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello, World!";
    }
}
@RestController
@RequestMapping("/api")
public class MyController {

    @RequestMapping("/hello")
    public String hello() {
        return "Hello, World!";
    }
}
@Controller
public class MyController {

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    @ResponseBody
    public String hello() {
        return "Hello, World!";
    }
}

@Configuration
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}
@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}
@RestController
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}
@Component
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}

@Cacheable("articles")
public Article getArticleById(Long id) {
    return articleRepository.findById(id).orElse(null);
}



@PostMapping("/articles")
public ResponseEntity<Article> createArticle(@RequestBody Article article) {
    // Save article logic
    return ResponseEntity.status(HttpStatus.CREATED).body(savedArticle);
}




@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeRequests()
                .antMatchers("/api/**").hasRole("ADMIN")
                .anyRequest().permitAll()
                .and()
            .httpBasic();
    }
}
@SpringBootApplication
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/api/**").authenticated()
                .anyRequest().permitAll()
                .and()
            .httpBasic();
    }
}
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/api/**").authenticated()
                .anyRequest().permitAll()
                .and()
            .httpBasic()
                .and()
            .csrf().disable();
  
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/api/**").permitAll()
                .anyRequest().authenticated()
                .and()
            .httpBasic();
    }
}

@Bean
@ConditionalOnProperty(name = "app.feature.enabled", havingValue = "true")
public MyFeature myFeature() {
    return new MyFeature();
}




@Scheduled(fixedRate = 2000)
public void reportCurrentTime() {
    System.out.println("Current time: " + new Date());
}