CREATE TABLE Customer_Details ( Customer_Id int(4) auto_increment, C_FirstName char(20), C_LastName char(20), PRIMARY KEY (Customer_Id), C_Temperature decimal(5,2), Mail_Id …
Tag: sql
SQL query for most recent date
I’m trying to query to only pull the most recent sale date but keep the unique value of “strap”. This is the query result I have. nh_cd strap dor_cd acreage sqft sale date …
Do any databases get NULL and “NULL” confused, or is it always an application design failure?
I’ve read a few articles like this one about a license plate value of NULL (about Droogie from DEF CON 27), including part of chapter three Little Data in the book Humble Pi by Matt Parker (talking about Steve Null), where storing a string value of “NULL” in a database matches NULL values. With databases I’ve used (at least AFAIK),
Show the manufacturers that sold cellphone in 2010 but didn’t in 2009. (USING MYSQL)
SELECT Manufacturer_Name FROM DIM_MANUFACTURER INNER JOIN DIM_MODEL ON DIM_MANUFACTURER.IDManufacturer = DIM_MODEL.IDManufacturer WHERE DIM_MANUFACTURER.IDManufacturer IN ( …
Trying to convert SQL getdate into varchar with no in-between characters
I have a list of auto-generated tables in MS-SQLServer that differ only in the date listed at the end of the name. The challenge is that I want to create a script that always references a table ‘x …
How do you update multiple rows in one column in a query?
In my table I have a column called test3 which has 8 rows in it, values ranging from 6 to 9, I am trying to use an UPDATE statement in SQL to update all of the rows in test3 but it doesn’t seem to …
Find unique subset
I’m trying to query 4 columns A, B, C and D to find records where there is more than 1 D per A/B. Relationship is hierarchical from A to D; there can be multiple Ds per C, multiple Cs per B etc. e.g. …
Failed to add the foreign key constraint. Missing index for constraint * in the referenced table *
system info SHOW VARIABLES LIKE “%version%”; when i create table in database with following statements it sucked. CREATE TABLE flavors ( created_at DATETIME, updated_at DATETIME, …
Does DB2 implement multi-table indexes?
I’m afraid this functionality may not exist [yet]. I wanted to use an index that spans multiple tables in DB2. I know Oracle and SQL server implement them (with more or less options) and that …
Randomly flagging records in an Oracle Table
Given a table of IDs in an Oracle database, what is the best method to randomly flag (x) percent of them? In the example below, I am randomly flagging 20% of all records. ID ELIG 1 0 2 0 3 0 4 …