Skip to content

SQL Query subquery with COUNT()

I’m trying to return the ‘conm’ that has 79 rows only. Here is my query: SELECT * FROM combinedata1 WHERE EXISTS ( SELECT conm, COUNT(conm) AS ‘Number of Rows’ FROM combinedata1 …

System Catalog vs Information Schema

When looking at SQL Server Management Studio (SSMS), which one is better and why? Are there cases where we should use one over the other? I can’t tell the difference between them. Answer INFORMATION_SCHEMA is there for compatibility, it doesn’t expose all the information about objects on the insta…

Country-wise Analysis of Movies

Write a query to find the number of movies rented across each country. Display only those countries where at least one movie was rented. Arrange these countries in the alphabetical order. DB: https://dev.mysql.com/doc/sakila/en/sakila-structure.html Below is the written code my output is displayed as below Ho…

Cascade DELETE to row of another table

CREATE OR REPLACE FUNCTION removerCapitulo() RETURNS trigger AS $BODY$ declare counter int; BEGIN select count(*) into counter FROM capitulos where id_capitulo = NEW.id_livro; if (counter >1) …