Skip to content

Tag: sql

How add more rows when find string in column Oracle

Would it be possible to add more rows base on Keyword string in SQL ? table A table B Example: Output of the SQL should be – How to find string with keyword ‘FamilyCare’ in PromotionName of table A base on promotion_code of table B? If it exist it will add more rows in output Any help with t…

MySql view with group_by very slow

I have two tables, appointments and clients. The tables are big, each with about 100M records. each has a primary key on id clients has a foreign key on appointment_id I’m using mysql 5.7 As one would expect, the following query is lightning fast: But, if I create the following view and query, it is int…

LEFT Join on a Subquery with specific criteria

I have two tables that I am trying to JOIN I am attempting to Select from table1 a and LEFT JOIN table2 b on a.id = b.id – however, I want to only select on the id in table2 where MAX(EndDt) Is something like that doable? Answer There are a few ways you can do this. I make some assumptions

Separate user role in SQL

I have a table called user_role_link where the column are userid, roleid, bitlive and bitdeleted. This table links to the dbo.user_role where in here I have columns roleid, DescriptionRole I want to extract all the users with introleid in (256, 308, 313) but not to be part of this roles: introleid NOT IN (225…

Which keywords did I missed on the following tables?

My problem: I get the same error on the tables: Tasks, TimeSheet, TimeSheetHour. I still don’t have any idea on what keywords did I missed. Here is the error I got in Tasks table: (same with other tables) May I know which keywords did I missed on the following tables? Answer The keyword is REFERENCES no…

Three table join with matched and unmatched records

I have three tables: store article_to_store article table. I need all articles with the store name. For all articles, I want to list all stores store table contains 3 stores. article table contains 2 articles. article_to_store relation table maybe has 2 records. One article in 2 stores. I need a mysql query w…

How to check whether a user has records in past?

Sample Table Above sample table consists Users info who completed certifications. An user can also go for retraining but he/she should have completed a course before retaking it. User Id: 2 is retrained on certificate 2, he has a record in past (Completed same certificate earlier), but User id: 3 has no certi…