I have 2 tables. 1st table contain the columns which are: 2nd table contains the columns which are: If both the component ID in both tables matches (Ex :component 1 in table1= component 1 in table 2), return all the rows matched with component in table 2. I am new to SQL and I am finding it difficult to do
Tag: sql
SQL output in one row
For example, I “select * from posts where id = 2” It will output all of the “id 2” information in 1 row After normalization, it have a new table for many to many relation. but I want to know that how can I output the result such as before normalization? Or I need to modify the output i…
Find the average over the n last purchases, for every user in the table using SQL
I have a SQLite db with two tables: users userID field1 field2 field3 field4 1 2 3 purchases purchaseID userID price timestamp 1 2 70 5166323 2 1 30 6543654 3 1 100 5456434 4 2 30 5846541 5 2 40 9635322 6 1 50 2541541 I want to write an SQL query that returns a table userID field1 field2
How to show current login User details in profile using ASP.NET MVC
I want to show user details on User Profile using Session but it is not working any other way kindly suggest me, I’m using ASP.NET MVC. Login class: Dashboard controller: Screenshot of output: Answer When you use a session, that session is available throughout the site based on how long you have given i…
Generate a range of records depending on from-to dates
I have a table of records like this: Item From To A 2018-01-03 2018-03-16 B 2021-05-25 2021-11-10 The output of select should look like: Item Month Year A 01 2018 A 02 2018 A 03 2018 B 05 2021 B 06 2021 B 07 2021 B 08 2021 Also the range should not exceed the current month. In example above
Find min and max data column in Table
I have a table that specifies exactly what date and time each employee was in a particular office. EmployeeTable looks like this: id EmployeeID DateP TimeP 1 11111 1397/01/02 01:30 2 11111 1398/05/09 05:30 3 11111 1398/06/07 05:10 4 22222 1398/08/09 06:12 5 22222 1399/02/01 07:15 6 11111 1399/07/02 08:51 7 11…
Oracle save updated rows in log
I have an update in my stored procedure. I would like to, save in my log the number of rows updated. How can I achieve this? Answer You can do something like this:
SQL Substring Case Condition
I’m trying to solve the following question on SQLPAD. Write a query to return the number of actors whose first name starts with ‘A’, ‘B’, ‘C’, or others. The order of your results doesn’t matter. You need to return 2 columns: The first column is the group of act…
How can I find a record that equals a value inside a JSON array
I have the following Table mytable I’m trying to query where id = 2 and partNum = 2423 Here is what I wrote so far: What would be the most efficient way to query? Answer Here is what worked for me.
Select clause result as comparison expression
In Sql queries can I use the result of a select clause using aggregate functions as an expression for a comparison? For example: Answer Yes, you can do this. You just need parentheses as you would with any subquery: Note that count(b) is not necessary when you know that b is not NULL. There is no need to chec…