I’m trying to run in Amazon Redshift, but I’m getting this error: SQL Error [500310] [0A000]: Amazon Invalid operation: cannot alter column “column_name” of relation “table_name”, target column size 256 should be greater or equal to current maximum column size 879; I’…
How to drop duplicate rows from postgresql sql table
I have the following dataset in a postgresql table called testtable in testdb. I have accidentally copied over the database and duplicated rows. How can I delete the duplicates? Row 1 and row 5 are copies in this frame and row 2 and row 4 are copies too. I have never used sql before to drop duplicates I have …
Delete record from table if certain fields are empty upon closing a Form
I am trying to get a button to close a Form and at the same time delete records on a table where certain fields are empty. I have this on the Form: AlimentoporTanque is the Table’s name and Tanques and Alimento the fields that should not be empty. When I click on the button I get following MsbBox poppin…
How to compare two sets in MySQL or SQL SERVER?
In this University Database: CREATE TABLE Stud( [S#] INT PRIMARY KEY, Sname NVARCHAR(50), City NVARCHAR(50), GPA FLOAT, [Clg#] SMALLINT ); CREATE TABLE Sec( [Sec#] SMALLINT, …
Canonical way to store reciprocal data sql
I got a lot of instances of the same Class. Now these objects can be linked and this link can have a weight. Like in an undirected graph. Now I want to store the relationship between each two objects in my mysql database. Data looks like this I could do create a table with this structure: object1_id | object2…
How to select distinct value from multiple tables given a column filter?
I have this table Products Id ProductName ProductCode 1 Alexa P0001 2 Alexa P0002 3 Alexa 2 P0003 4 Aquarium P0004 5 Aquarium X P0004 6 Bathtub P0005 Scenario 1: Expected Result: Returns distinct ProductName along with Id Id ProductName 1 Alexa 3 Alexa 2 4 Aquarium 5 Aquarium X Actual result: Returns all prod…
Using the Union function in SQL to reverse columns
I have the following SQL code to produce the following table of data: I am hoping to transform data to create a table that looks like: What would be the best way to achieve this? Something like creating two tables and then a Union join? Answer You can use self join to achieve what are you looking for. Schema:…
python tuple in sql string
I have a sql query like this: “…AND A IN (12,13,14)…” now I want to replace the (12,13,14) with a python tuple that may contain far more than 3 three elements. In Matlab, I can simply …
STUFF only unique values along with sorting another column
I want to combine values with comma-separated. For that used stuff. But my data has duplicate values, and I just need unique items from that. Here is a query that I’m using. SELECT STUFF ( RTRIM …
Optimizing JOIN and WHERE operation in SQL query
Below is an sample query. On a glimpse I’m trying to figure out how to optimize this query better, I’m trying to reduce the OR operator at the WHERE option at the bottom but I haven’t figure out how. …