I have 2 lists of IDs and I need to return a list with the products that aren’t in any of those lists: public IEnumerable GetProdutosIdNotInFamily(Guid produtoId) { …
Select all distinct last records of column1 and order by column2 in Linq (Not Working Accordingly)
So I have a table like this: Now I want distinct ShortCode order by the ID descending. In other words, the distinct last records. Like this: So I tried GroupBy like: var data = db.ShortCodes.GroupBy(…
Java SQL problem executing query through CallableStatement with parameter
I have a problem in a CallableStatement that execute a stored procedure query which accept a parameter. I have a list of string that contains the query like: I have a list of string that contains the parameter like I have no SQL syntax error when I run but the result set doesn’t have any value. The expe…
How do I count events in chronological order in SQL?
I’d like to aggregate Talbe_A and make it like Table_B. It is difficult for me to count events according to the time order. How should I write a Query? Table_A client_id event time A …
SQL Having, but in Javascript way
So I came up here in the javascript to convert the SQL Query but using Javascript. the following SQL statement lists the number of customers in each country. Only include countries with more than 5 …
Condition within aggregate query vs math
I have these two query examples with small difference that i thought would be performance optimization but there is no difference. The small change is that in one of the queries there is conditional logic within the aggregate while in the other one i use simple math to get the same result. I would have though…
Reserve a range of values in a table in SQL Server
I want to reserve a range of values for the system like [1-10,000]. The user values should be inserted after 10,000. eg. There is a table that will have values inserted by the system & will also have values inserted by the user. So, when a system inserts, the id’s assigned to it will have to be betw…
Laravel Load Relation With Condition On Model
I’m attempting to eager load a user’s notifications with a relation that depends on a value of notification model: $notifications = $user->notifications() ->with([ ‘notifiable’ => …
Dynamic Pivot Table by Month
I’m trying to create a dynamic pivot table in SQL that will report based on month and year. I did a bunch of research and was able to come up with the below query: I am able to print the @column variable successfully, but the problems happen when I try to set it in the @dynamic variable. The error messa…
Inserting Multiple of same records into SQL temp table based on value in column
So I have table with the following records: I want to create a script to iteratively look at the Cnt_Repeat column and insert that same record in a temp table X times depending on the value in Cnt_Repeat so it would look like the following table: Answer One method supported by most databases is the use of rec…