SQL – is there a way to order results by how many `OR`'s it maches? (laravel)

I have this query: SELECT * FROM articles WHERE name LIKE ‘%test%’ OR title LIKE ‘%test%’ OR text LIKE ‘%test%’ OR author LIKE ‘%test%’ The (known) results are composed of records that match the first condition, others that match the second and so on.. However – some of them will match more than one condition.… Read More SQL – is there a way to order results by how many `OR`'s it maches? (laravel)

SQL–How can I add a constraint based on multiple joined tables in an INSERT statement?

I am attempting to limit the creation of a new record in a cross table to Active records in the respective primary tables. In this example, the Owners table and the Pets table each contain an ‘Active’ column with a boolean data type. The cross table contains columns for OwnerId and PetId. I do not… Read More SQL–How can I add a constraint based on multiple joined tables in an INSERT statement?

SQL return multiple columns based of there max date and the date is less than certain value

What I am trying to do is find the ‘newest’ Ad Rates based on its date. I need to return multiple columns which will be grouped by the store. I am using SSMS. and below is a screen shot of what the table looks like with all the values. Disregard the Id. As you will… Read More SQL return multiple columns based of there max date and the date is less than certain value

how to convert this OR operator to case statement

i have the below query, i want to know about the case statement by changing the below type of operator. SELECT t_product.a_productid, t_product.a_mpactive, t_product.a_active, trim(substring_index(a_reference,’_’,-1)) as a_reference, t_product.a_shopid, t_productlang.a_name, t_deactivatedproduct.a_reason FROM t_deactivatedproduct inner join (SELECT max(a_deactivatedproductid) as a_deactivatedproductid FROM t_deactivatedproduct GROUP by t_deactivatedproduct.a_productid) as a on a.a_deactivatedproductid = t_deactivatedproduct.a_deactivatedproductid INNER JOIN t_product ON t_product.a_productid =… Read More how to convert this OR operator to case statement

Postgres – Pass dynamically generated date to where clause

I need to generate series of date till current_date based on job’s last run date last run date =’2022-10-01′ current date = ‘2022-10-05’ generate date like varchar dynamic_date = ‘2022-10-01′,’2022-10-02′,’2022-10-03′,’2022-10-04′,’2022-10-05’ and pass to where to clause select * from t1 where created_date in (dynamic_date) this is not allowed as dynamic_date is varchar and created_date is… Read More Postgres – Pass dynamically generated date to where clause

SQL checking equality inside a case statement inside where clause?

Here is the code: WHERE 1=1 AND TU.Auction_I IN (41, 42) AND @StatePickupID = CASE WHEN @StatePickupID IS NOT NULL THEN (UP.TransportStateID = @StatePickupID) END AND @StateDropoffID = CASE WHEN @StateDropoffID IS NOT NULL THEN (UD.TransportStateID = @StateDropoffID) END So I only want to return records where UP.TransportStateID is equal to StatePickupID if it is… Read More SQL checking equality inside a case statement inside where clause?

Selecting specific columns in where condition using Pandas

I have a below Dataframe with 3 columns: df = DataFrame(query, columns=["Processid", "Processdate", "ISofficial"]) In Below code, I get Processdate based on Processid==204 (without Column Names): result = df[df.Processid == 204].Processdate.to_string(index=False) But I wan the same result for Two columns at once without column names, Something like below code: result = df[df.Processid == 204].df["Processdate","ISofficial"].to_string(index=False) I… Read More Selecting specific columns in where condition using Pandas