I have 3 tables: Table 1 id | email —+———- 1 | a@a.com 2 | b@a.com 3 | c@a.com 4 | d@a.com Table 2 order_id | email ———+————– 1 | a@a.com 2 …
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…
Microsoft Access – How do I import data to an existing Table and update the data
simple yet, a question I can not find an answer too. I am currently importing RAW Data from Excel to my ACCESS database. Every day, this RAW data I receive updates in status. I have a field/key that never changes for example a Document number. However, fields like “Status” and “quantity̶…
Single-row subquery returns more than one row BUT with one row
“CityJail” schema. I am supposed to find each appeal that has a less than the average number of days between the filing and hearing dates. Here is my code: I get an error: ORA-01427: single-row subquery returns more than one row 01427. 00000 – “single-row subquery returns more than one…
BigQuery get row above empty column
Data: What would be the best way to get the row right above the empty cell? For example, I’d like to filter out row 1 and 3 based on the fact that column_b in row 2 and 4 are empty (in this example). A simple where statement does not work unfortunately, but how would it be possible to get the
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.