When I try to select couple of columns with count, I get the following error: Selected non-aggregate values must be part of the associated group My query is something like this. Answer If you’re after a count for each combination of COLUMN1 and COLUMN2: If you’re after a count of all records in th…
Oracle SQL Loader – How to not display “Commit point reached – logical record count” counts
I’m loading big files via Oracle SQL Loader over vpn from home, and they’re taking a lot of time. They were a lot faster to load when I loaded them from work. The files I’m loading are on my work server already. So my thinking is that the slow down is because of the “Commit point reach…
alter column table and make default value to empty string
good day.. just want to ask, is it possible to alter a column table and make the default value to empty string.. i tried using this query, Alter Table Employee Alter Column sJobTitle Varchar(…
How to store historical records in a history table in SQL Server
I have 2 tables, Table-A and Table-A-History. Table-A contains current data rows. Table-A-History contains historical data I would like to have the most current row of my data in Table-A, and Table-A-History containing historical rows. I can think of 2 ways to accomplish this: whenever a new data row is avail…
Problems with Postgresql CASE syntax
Here is my SQL query: When I execute the above query, I get this error: ERROR: CASE types record and integer cannot be matched From the error message I understand that PostgreSQL take the second select, respectively elapsed_time_from_first_login as a row, even if it will always be a single value (because of t…
SQL Column definition : default value and not null redundant?
I’ve seen many times the following syntax which defines a column in a create/alter DDL statement: The question is: since a default value is specified, is it necessary to also specify that the column should not accept NULLs ? In other words, doesn’t DEFAULT render NOT NULL redundant ? Answer DEFAUL…
Delete many records from table A and B with one FK to table B
I have 2 tables: A and B A contains the following columns: B contains the following: B has a reference to A from A_id column (FK) The question: I want to delete all records from table A that their checkpoint_id is less than X: But I can’t do it since “The primary key value cannot be deleted becaus…
sqlalchemy simple example of `sum`, `average`, `min`, `max`
For sqlalchemy, Who can gently give simple examples of SQL functions like sum, average, min, max, for a column (score in the following as an example). As for this mapper: Answer See SQL Expression Language Tutorial for the usage. The code below shows the usage:
Combine multiple SELECT statements
I’ve used Excel to generate numerous SELECT statements from a list of the schema names from a database with a large number of identical schemas: select result from foo.table limit 1; select result …
Inner Joining three tables
I have three tables I wish to inner join by a common column between them. Say my tables are; TableA TableB TableC I wish to join A-B, but then also B-C all by this common field I will call common. …