Skip to content

Tag: sql

SQL Query ORDER BY column values

I have a column which can take any values from 0 to 100. Now i have a type TYPE1 which can take values 2, 4, 16 TYPE2 which can take values 8,12,64. Now i want to sort the column by TYPE1 values first and then TYPE2 values. Is there any way to do that. My column has only these values.

BatchSqlUpdate – how to get auto generated keys

I am using spring BatchSqlUpdate to insert a set of rows. How do I get the auto generated keys for all of the rows inserted? When doing a single insert I get the keys like this – Thanks! Answer There is no provided solution for this using BatchSqlUpdate as far as I know, but you can always query the las…

Get last record of a table in Postgres

I’m using Postgres and cannot manage to get the last record of my table: How can I do that knowning that timestamp is a unique identifier of the record ? Answer If under “last record” you mean the record which has the latest timestamp value, then try this:

MySQL syntax: What is this?

My exported SQL file contains the lines below: What do these lines mean, unlike CREATE TABLE and INSERT INTO? Answer They are variable assignments. The assignments are wrapped in executable comments in such a way that they are executed when MySQL is used and left alone if some other RDBMS is used. Furthermore…

Count number of occurrences in SQL

I have a table with the following structure: (table_name, column_name) and for each row in this table I need to query the column_name in the table_name and do a COUNT(column_name) GROUP BY …