I have TWO simple VIEWS with columns PID and NAME respectively. Here’s how they are connected to each other. View1: PID NAME Comp1 , C1 Comp2 , C2 View2: PID NAME ParentPID …
Tag: union
select rows with events related with another events in the same query column
I need to select rows with EventTypeID = 19 which does not have related EventtypeID = 21 LoggedOn exactly 4 minutes earlier for the same EmployeeID. Here’s the query bellow and some raw output: …
T-SQL Union (distinct, not all) and Order by with priority
Assume I have a Tag table (Id int and Name nvarchar(100)) with 3 values: 1 Software 2 Hardware 3 Warehouse Now I want to query with keyword, and prioritize the ones that starts with the keyword over …
Query to find the city name with longest and shortest length
I’ve written a query to return me the cities with the shortest and longest length strings in a MS SQL SERVER database. Select city, len(city) as l From Station Where len(city) in ((select max(len(…
Oracle SQL Unions error “query block has incorrect number of results columns”
I’m trying to write a query that pulls data from a lot of tables, and has about 20 unions. It’s pulling the same information repeatedly, but with more layers each time, to show a sort of tree. I want to compare the final two columns. I’m using a case to do this, and if I add a case to this
Is order preserved after UNION in PostgreSQL?
Here is the code: As you can see the recursive code gives the result in right order, but the non-recursive code does not. They both use union, why the difference? Answer Basically, your query is incorrect to begin with. Use UNION ALL, not UNION or you would incorrectly remove duplicate entries. (There is nothing to say the trail cannot switch
MYSQL: UNION results between two tables where omitting records from first table if PK found in second table
I have two tables products and product_edits which hold product information on the pricelist. My app works in a way that if user changes any product info in products table it inserts it into …
Performing an UPDATE with Union in SQL
If I were to have these three tables (just an example in order to learn UNION, these are not real tables): Tables with their columns: And I wanted to update order_status in the Customer table when there is a order filled in either the Order_Web table or the Order table for that customer using Union: How can I combine these
Combine multiple SELECT statements
I’ve used Excel to generate numerous SELECT statements from a list of the schema names from a database with a large number of identical schemas: select result from foo.table limit 1; select result …
Combining UNION and LIMIT operations in MySQL query
I have a Jobs and a Companies table, and I want to extract 20 jobs that meet the following criteria: Jobs only from two (2) named companies There can at most be 10 jobs per company I have tried the following SELECT with UNION DISTINCT, but the problem is that the LIMIT 0,10 applies to the whole result set. I