I have two tables, table one name (tbl_brands) with these columns: and second table name (tbl_loader_attachment) with these columns: I used this MySQL code below to sort by DESC: SELECT …
Should I create a separate table in MySQL when I have fixed number of possible values for a field?
I’m doing some database optimization and I was wandering, if I have a table Users, and that table has a _status field, should I be creating a separate table for status codes like so: Table statuses: …
SQL return values from one table depending on another table
I have 2 tables – IdentificationChallenges and IdentificationResults. The challenges table shows a list of challenges and the results table stores a users attempt at the challenge. I need a query to …
Set column value of a view based on which table I’m selecting from
I’m creating a view from 2 tables. I need to create a brand new column in the view; this column must be set to 0 when I’m selecting from the first table, 1 from the second one: Table A: +———+—…
Subquery as Join?
My query is shown below. SELECT *, SUM(A.money_step) over ( partition by A.id_key, A.P ORDER BY A.actual_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW )as accumulated FROM ( …
How do I pagination using query limit, offset, and jquery datatable?
I made a page using the data table. However, as the number of data increases, the speed of data loading slows down, so we try to proceed paging. But I don’t know how to modify it in the current code. …
Need to filter all rows in postgres where records share a common id but any one fails to pass a subquery
I have a table in Postgres that looks something like this: The algorithm is if any single record has reversed = true or status = foo, all records with the same group_id should be filtered. If group_id is null, which is possible, I’d like to keep those records regardless of reversed or status The closest…
Python problem with adding table to Database with sql
Hi, I’m trying to create a function that will take a table in insert(add) to the database. My Code : this is the old code when i didn’t create a function: Answer You seem to have put table_name under quotations in your to_sql function. Also, you seem to be tackling the issue of data model creation and mainten…
Check Constraint with Filtering Logic
I have a table that has bit column called “Flag” it does not allow NULL. A requirement here is to ALWAYS have Flag=1 set for every Id in the table below but only 1 time per each unique Id and Flag columns combination. At the same time all other rows can be have Flag=0 set multiple times if there a…
SQL iterate UPDATE from python list
Do you guys know how to UPDATE a database from a python list without using cur.executemany? Using cur.executemany I have problems in API calls or something. What is another way to solve this below? Thank you! I know below is crazy ugly, but I did that. Answer Not an answer but I don’t want to edit your …