I’d like to select order items from all orders with a specific item. In SQL I’d do it like this: How would I do this query with the query builder? Answer This is how I would try it: I didn’t test this of course, and made some assumptions about your models. Possible problems: Limit: this has been somewhat of a
Tag: database
MySQL PRIMARY KEYs: UUID / GUID vs BIGINT (timestamp+random)
tl;dr: Is assigning rows IDs of {unixtimestamp}{randomdigits} (such as 1308022796123456) as a BIGINT a good idea if I don’t want to deal with UUIDs? Just wondering if anyone has some insight into …
Select NULL Values in SQLAlchemy
Here’s my (PostgreSQL) table — I want to select all people that are not known to be married, i.e., including those with NULL marriage_status. This does not work — Of course this does — The problem is that I’m accessing it from SQLAlchemy with — which gets translated to — And does not work — neither does — How should
Join query on Date Range
HI I have following tables and so on for whole year I want the following output I need to take join between these two tables but i couldn’t figure how join condition will be look like Ragards Answer
How to do a batch insert in MySQL
I have 1-many number of records that need to be entered into a table. What is the best way to do this in a query? Should I just make a loop and insert one record per iteration? Or is there a better way? Answer From the MySQL manual INSERT statements that use VALUES syntax can insert multiple rows. To do
PostgreSQL: SQL script to get a list of all tables that have a particular column as foreign key
I’m using PostgreSQL and I’m trying to list all the tables that have a particular column from a table as a foreign-key/reference. Can this be done? I’m sure this information is stored somewhere in information_schema but I have no idea how to start querying it. Answer This uses the full catalog/schema/name triplet to identify a db table from all 3
NOT DEFERRABLE versus DEFERRABLE INITIALLY IMMEDIATE
I read this about the SQL keyword DEFERRABLE in Database Systems – The Complete Book. The latter [NOT DEFERRABLE] is default, and means that every time a database modification statement is executed, the constraint is checked immediately afterwards, if the modification could violate the foreign-key constraint. However, if we declare a constraint to be DEFERRABLE, then we have the option
Right query to get the current number of connections in a PostgreSQL DB
Which of the following two is more accurate? Answer Those two requires aren’t equivalent. The equivalent version of the first one would be: In that case, I would expect that version to be slightly faster than the second one, simply because it has fewer rows to count. But you are not likely going to be able to measure a difference.
Freeware Query Builder [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 7 years ago. Improve this question I’m looking for some freeware Query Builder. Query Builder in Aqua Data Studio allows you to visually build queries: select the column you want
MySQL query finding values in a comma separated string
I have a field COLORS (varchar(50)) in a my table SHIRTS that contains a comma delimited string such as 1,2,5,12,15,. Each number representing the available colors. When running the query select * from shirts where colors like ‘%1%’ to get all the red shirts (color=1), I also get the shirts whose color is grey (=12) and orange (=15). How should