I have the following two tables: My goal is to do a (left?) join and get all matching rows in the child table based on the FK in an array on the parent row and not inside the parent row itself on matching column names (see further down on desired output). Examples of values in tables: Parent table: Child table:
Tag: sql-server
Replace OUTER APPLY
I want to replace some OUTER APPLYs in my SQL because they seem to be a little bit slow and eating resources () on a poor VPS. I have no idea what to use instead? LEFT OUTER JOIN (??) Here’s my code The query processor ran out of internal resources and could not produce a query plan. This is a
How to Use Queries to show records based on conditions
I have an SQL query that selects data based on uploaded and not uploaded this is the query am using to achieve the data above I want to go a step further and group the data into two columns. I want to get the labnames grouped using the uploadstatus that is 0 as Not Uploaded and the ones having 1
Transforming a sheet into a table with column names as values in SQL Server
I’ve been given the task of turning the following Excel table into a database table in SQL Server (I have shortened the row count, of course). A car has to go to service every 10.000 kilometers, but for some models there is a fast service that applies only to certain mileages (I don’t know what mileage is called in kilometers
How to create a trigger for this situation?
I have a problem inserting values into a Class table. I want to write a trigger to prevent happening “an instructor teaches in different class_Id at the same time”. How can I do this? This is the trigger which I’ve created: Answer Use inserted and JOIN to the Class table. Check for existence of rows in table that matches your
Calculation using SQL server
Formula used This is the formula that I used to calculate Expressed as a single equation: Code that I tried Correct answer should be 123. Any clue what I am missing in the query? Answer According to this site your equation is kinda wrong. Please be sure to add ^ to display the “to the power of”. Also this result
Removing SQL Rows from Query if two rows have an identical ID but differences in the columns
I´m currently working stuck on a SQL issue (well, mainly because I can´t find a way to google it and my SQL skills do not suffice to solve it myself) I´m working on a system where documents are edited. If the editing process is finished, users mark the document as solved. In the MSSQL database, the corresponding row is not
Matching multiple columns based on groupID from another table’s data
I have 2 tables, one where I have sets of information that is organized by group ID’s. This group ID means all parts must be in that group for that machine to be an option: Machine Part Group 1 Part Group 2 GroupID Mach A Part M Part A 1 Mach A Part M Part B 1 Mach A Part
Get Substring between two characters in SQL Server query
I want to get the string between two characters in the following string: I want to get the text between the @ and the SPACE after the @ which results in user1, is there a way to do this? There could even be 2 or more @ which I will need to extract like here is a table-like example: Sample
Table recursive lookup on itself
I have the following table below. I want to select all of the members of Group-D However, Group-D also contains Group-C along with User 5. Group-C contains Group-A and Group-B. So, the select should return: Obviously, without doing multiple lookups on itself, I will not get that output. How can I make the select statement do a table lookup within