Skip to content

Tag: sql

A self join query

Given this relational schema people (pid, name, gender, age, email, city, state) books (ISBN, title, edition, publisher, year, rating) write (pid, ISBN) pid is a foreign key and refers to people (pid), ISBN is a foreign key and refers to books (ISBN) I need to write a SQL query to find the authors who either …

Update field with values from a select query/subquery in SQL

Hello I need to select a specific string form a field one table and then populate another field in a different table in the same SQL database. I am extracting the date from a field. The characters are between two underscores. I was able to create the Select statement correctly using guidance from a previous p…

Finding daily registered users

I have a table which includes the information of player_id, first_timestamp, last_timestamp, and date, etc. So I have initially 10 payers on 2020-07-08, and then 18 players on 2020-07-09, some of the players from previous day might appear on 2020-07-09 again. And I’m trying to find the new players regis…

WHERE a AND b returns just WHERE b

I have 2 tables which I want to join and return only those records which: Have the same value with other records in one of the columns. Have certain values in other column. These are my requests: List only those records which have the same value with other records in grnz column: List only those records which…

SQL subquery to find overlapping customers

I’m working on writing a SQL query that would allow me to find customers who bought a certain variety of a product during specific sale dates and then subsequently bought a different product within a different date range. I want to use a subquery in the from clause to search for the second group of cust…

Count NULL values by column in SQL

Suppose I have the following table: How can I count the number of NULL values by each column? My final result would be: Answer You can use union all: Redshift is a column-store database, so there probably is not a more efficient method.