Skip to content
Advertisement

Django many-to-many: Best way to get elements in one related query set but exclude elements in other related query sets?

Consider these related models: In a view, I need to query to get all Bs related to a given A while excluding all Bs related with a set of other As. I need the grey area: My current, grossly inefficient approach is as follows: In my application, previous_As could have nearly 1,000 elements, which makes this approach extremely expensive. Is

I want to echo all classNames that have the same userid in php

code here : I am trying to echo all instances where the userId in the classrooms table is equal to the session userId. HELP. this is the table that we are using to track the users classrooms I’m using mysqli. Turns out, my post is mostly code. So let me give some background details. I’m trying to make a table

How to merge columns and transpose in SQL?

I’m working with a custom DBMS (compliant with SQL 2011 Standard), and am trying to combine multiple columns into a single column like so, but am struggling with the syntax: Current table: Desired query output: I’ve tried various IF and CASE statements, but have hit a wall. Any help would be appreciated. Answer You can unpivot with union all: This

SQL Query, loop through data

I have a database with the following fields: UserID, DateRecorded and Score. A new entry is added to the table each time the score is updated. Here is an example of a user record: From the query I would like it to show me only the scores of all users with the earliest DateRecorded. Although not much familiar with cursors,

SQL Server 18 – merging dates around midnight

I would like to ask if anyone could help me with this. I have a table with user traffic on websites. The important column is Timestamp which looks like this. Timestamps are used to calculate sessions. An hour or so in timestamps means one session. The problem is that calculated session is different when the activity on the websites was

Nasty sql error(POSTGRES) “There is no unique constraint matching given keys for referenced table…”

EDIT: tables have been translated from my language to english i’ve changed te reference of foreign key in table Comment to “Utente” -> “User” Hi everyone i’m trying to build a small review system in sql as follows. Every user can comment on some item(could be anything) and any other user can answer any comment. The Admin of the website

Advertisement