Suppose I have two tables t and o. I want to select all the rows of t in which t.feature = o.feature (ergo first two rows). In addition, I also want to select all the rows whose t.grouping = t.grouping of the previously selected rows. In this case t.grouping 1, 2 ergo rows (‘E’, 1), (‘F̵…
Oracle SQL return column calculated from existing columns
I have the above SQL query which returns the columns name, X and Y. I would like to return one more column (lets call it Z) which gives the value of X/Y but not too sure how to do this – I tried writing (X/Y) Z but no luck – any suggestions? Answer Use CTE
Delete records with duplicates and join in another table
I need to write a query (Microsoft SQL Server) to delete duplicates in the table Vehicle that have Vehicle.CarId = Car.CarId and having the same concatenation (CarId, CounterLimit, Kilometers). Table Car: Table Vehicle: Could you please help me? Answer Joining the table creating the rank based on carid,counte…
How to count a foreign key and use it to sort the primary table?
I have 2 tables: Product (prod_id, prod_name, vend_id) Vendor (vend_id, vend_name, vend_state) I am trying to make a query that will give me a list of the vend_name for every vendor that supplied only one product. vend_id is a foreign key in Product, and I would like to count how many instances of each vend_i…
Column containing the product of elements in a second column, sorted by group
I have the following SQL script, , which yields, I wish to create a column, Product, that contains the product of Numbers on each date within the same BM group: To clarify, for BM =’AA’ the product should be 1*2*3*4*5=120. Thank you in advance! Best regards, Answer There isn’t a built-in pro…
How to change a column’s datatype from text to datetime in mysql?
I’m trying this but it’s not working. My original data is formatted like this month/date/year (eg: 2/24/20) Answer You should create a new datetime column and populate it using STR_TO_DATE with the text date: If you’d like, you may also drop the original date column, and then rename the new …
Comparing two tables without foreign key [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question There are two tables in 2 different databases one table consists of Salutations example Mr, Mi…
How to select all enteties grouped by common propertie without loop?
Is there any way to fatch all entities from table grouped by common property while loop? Table storage looks like this and final result supposed to look like this What i want is this: Select each record grouped by category id. It means, if table size is 3200, i need to select all of 3200 records grouped by ca…
SQL – Returning all rows that are not ‘vice versa’ of one another
I’ve got a situation as follows (note this setup has been created as a minimal reproducible example). I have a table of houses, created like this: I have a large table called house_listings, like this: So, let’s say I run the following query: and I get the following output: and then I run the foll…
MySQL query to Retrieve Main record from main table and Sub records from another table in a single SQL statement
I have following Two tables Table Name: category Table Name: product Now I am looking for single SQL statement which should retrieve everything in a single sql statement. Expected output given below: Answer You can use union all: