Is there any way to delete all the rows of a table if the value of one of the columns is null, without specifying the particular column?
I am dealing with a table that has a lot of columns, and it is not efficient to specify all of them, so I was wondering if something like this is possible?
Related
I have 2 tables TabA and TabB. Both don't have any key columns.
Column wise both are replica and have more than 80 columns.
TabA has 30 million records. TabB has 2000 records only.
Now I need to compare all the columns between both tables since NO key column is there and remove duplicate records from TabA.
I would like to find best approach to compare both tables instead of placing all 80 columns either in JOINS or WHERE clause.
If all 80 columns are needed to identify the record, you'd have a hard time not using all of them in your query, one way or another.
You could calculate a hashcode using HASHBYTES() on all the columns, and then compare only the resulting hashcode.
There's also CHECKSUM(*) function that calculates hash on all the columns, without the need to explicitly list them, but it returns int as a result, which is too weak if false positives now and then are not acceptable.
I have created mutiple tables inside a database using PhpMyAdmin. But I cant find out how to do this:
It should not be allowed with two identical names in one of my columns. The column is called "name".
And I have one column called "prod_time" and one called "stock_ant" that must be filled in. (Like it's not going to be an option to leave it blank or with zero value)
Is there multiple queries to use for these actions?
If you want a column to have unique values, use a unique constraint or index. For instance:
alter table t add constraint unq_t_name unique (name);
If you don't want columns to have NULL values, then declare them NOT NULL when you create the table.
I have two tables that store two sets of ID's which are the same, when any of the four ID's are NULL there's an issue on the front end application. These four values always vary as to which can be NULL but there will always be one with the correct entry.
My question is can I enter these four values into a temp table then update all the NULL values using the column which has actually has a value? As the column with the correct value changes all the time it makes it harder.
Basically i'm making a stored proc but can't figure this logic out.
It sounds like you just need to use coalesce to find the non-NULL value.
coalesce(table1.col1, table1.col2, table2,col1, table2.col2)
The only caveat is that if two columns have different non-NULL values, then this expression returns the first one (in the order you list the columns) it finds. But if you don't have that situation occur, or if you can specify which column you'd use when it does occur, this should work regardless of what combination of columns has NULL.
Using table expression to join two tables then from the result table, update the column missing data with the ones have.
We have a huge table and one of the column contains queries like e.g. in row 1
1. (((firstname:Adam OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Individual
and in row 2 of same column
2. (((firstname:Adam* OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Organization
Similarly there are few other types of Query strings which are used eventually to query external services.
Issue is based on certain criteria I have to group and remove duplicates from this table.
There are few rules to determine grouping of Strings in different rows.One of them is that if first name and lastname are same then ignore category and type values, therefore above two rows will be grouped to one. There are around million rows. Comparing Strings and doing grouping is not looking elegant solution. What could be best possible solution using sql.
How do delete duplicate records in a DB2 table? I want to be left with a single record for each group of dupes.
Create another table "no_dups" that has exactly the same columns as the table you want to eliminate the duplicates from. (You may want to add an identity column, just to make it easier to identify individual rows).
Insert into "no_dups", select distinct column1, column2...columnN from the original table. The "select distinct" should only bring back one row for every duplicate in the original table. If it doesn't you may have to alter the list of columns or have a closer look at your data, it may look like duplicate data but actually is not.
When step 2 is done, you will have your original table, and "no_dups" will have all the rows without duplicates. At this point you can do any number of things - drop and rename tables, or delete all from the original and insert into the original, select * from no_dups.
If you're running into problems identifying duplicates, and you've added an identity column to "no_dups," you should be able to delete rows one by one using the identity column value.