Skip to content
Advertisement

Tag: database

Multi-column IN/ANY postgres query

Sample table schema: Requirement: Fetch rows that match any of the tuples (col1, col2) presented in an array. SQL: I want to write this query in Go using the “database/sql” package with “github.com/lib/pq” driver, and that is where I am facing the problem. I can easily do this for single column IN/ANY query. for example, the following query can be

get all the tables within a date range

I have many weekly backup tables of the same structure and columns but with different names containing some user-specific information like this. Now I want to find the tables within a date range for example: If I choose the date range of 2021-11-20 to 2021-11-13 then the tables fetched would be user_details, user_details_20211126, user_details_20211119 for using them in a query

Query monitoring changes in the field

I need to program a query where I can see the changes that certain fields have undergone in a certain date period. Example: From the CAM_CONCEN table bring those records where the ACCOUNT_NUMBER undergoes a modification in the CONCTACT field in a period of 6 months before the date. I would be grateful if you can guide me. Answer You

FOR XML PATH produces only first item

I have two tables: Reservations and ReservationNights (every reservation has many nights). In a stored procedure, I have a variable that looks like this: @roomTypeList = ‘2;3;4;5;’ -> its a list of RoomUseIds. I need to display only the reservations that have a reservation nights with one of those Ids (In this example, it should display only reservation 14105, because

How does a multi-column index work in MySQL?

More specifically, what data structure does MYSQL use for multi-column indexing? I know MYSQL use Btree for indexing, which can only index one column. How does multi-column indexing work then? Answer Think of a MySQL “composite” index this way. Concatenate all the columns in the index together, then build an BTree index on that ‘single’ string. Some related comments: Once

How to select records from a Postgres table using an ORDER BY statement on a jsonb column that points to another table

I have two tables, characteristics and students. characteristics students The characteristics table has three columns where the id column is an auto-increment field. The name denotes the name of a specific characteristic and the value indicates the respective information about the characteristic. The students table contains detail about each student. The character_value field in the students table is a jsonb

Update column of a table with new foreign key of associated table

Let’s say I have a Persons and Books table that were associated. Currently persons.usercode serves as the primary key and hence the foreign key on associated tables. I would like to change the primary key of the persons table to persons.uid. So now I want the books table to look like Dropping and adding the new primary key constraint shouldn’t

Advertisement