Skip to content
Advertisement

Tag: sql

SQL query to display rows of 2 different tables

I’m trying to figure out how to pull all rows from two different tables with the OutageID = X. The purpose of this is to view the current outage and all the revisions in one statement to see all of the changes. Below is an example I was trying. However, it puts it all in one row. I want it

How do I find an order that contains all the available products?

I have a products table that contains all the available products, as well as the order_has_product table which contains all the products that should be included in every order. How do I find the order_id for any order that contains all the available products? Note how the order with an order_id of 1 contains all the available products. order_has_product: order_id

How to make postgres not use a particular index?

I have the following query: As you can see, the cost of the last index scan on chaindata_tokentransfer_chain_id_block_number_tx_eeeac2a4_idx is very high. And the query is timing out. If I remove the filter on chain_id and block_number from the query, then the query is executing in a reasonable amount of time. Since this new less constrained query is working, I’d expect

SQL: Pull rows based on sequence of values

I need to pull rows of data based on the existence of certain values that exist in a specific sequence. Here’s an example of the data: Header EventId EventDate 67891882 382 2022-01-21 09:29:50.000 67891882 81 2022-01-21 09:03:23.000 67891882 273 2022-01-21 09:03:51.000 67891882 77 2022-01-21 09:05:58.000 67891882 2 2022-01-21 09:29:48.000 The results I need are to capture the Header and the

Difference between CREATE CAST and CREATE CONVERSION

In postgres, it seems there are two customizable ways to convert one value type into another via SQL, CREATE CONVERSION and CREATE CAST. What is the difference between these two items, for example what might be an example of where one might be used over another? Answer A cast has nothing to do with a conversion. A cast converts data

How to use SQL to find specific names or words in a database?

I am working with a database of data from Reddit. I want to find the name and description of all subreddits where the name starts with “covid” or “corona” and the description contains “covid” anywhere. I then want to output a table that has two columns: name and description. So far, I have tried this SQL code: When I execute,

Return only the modified records in a table, using T-SQL

I’m attempting to return only the modified records in a table, using T-SQL. This is what I’ve done thus far: Results: Expected results: The following statement returns all the 0 to 1, and 1 to 0 records and I don’t understand why: Answer To track the changes at whole dataset, you were almost there, you just need to remove the

Select configurable column names in Oracle SQL

I have a table with configurable column names which I can query like this: This is how ‘my_config’ tables looks like. My other table would look like this: However, I would be looking to select only those columns that the query above returns in my other table, kind of like the below: How could I achieve this? Expected result: Answer

Find rows that have the same value and select the newer one

I got a table, that looks like this: serialNr sensorNr ModifyDate 1234 12EE56423 2022-04-06 4567 12EE56423 2018-06-12 6789 AD3FF0C44 2018-03-08 9101 AD3FF0C44 2019-06-07 From rows with the same sensorNr, I only want to select those with newer ModifyDate, so the result should look like this: serialNr sensorNr ModifyDate 1234 12EE56423 2022-04-06 9101 AD3FF0C44 2019-06-07 How can I achieve that? Answer

Advertisement