I need to display the current status of a part (‘approved’ or ‘not approved’) I am setting up the status table as MaterialNo, ToolID, Status, Asofdate the idea is I may have several tools approved and several not approved. I want to be able to see the most recent status for each tool b…
Tag: sql
How to select count between start to (start+length) [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 2 years ago. Improve this question How the following result appears when creating a table as above. This is the result of count…
Ordering an alias column in union query
I have a SQL query that utilises a union a few times, and within it I’ve created an alias column called ‘Category’. When I try a simple order by on the alias column it works fine. However the data in my alias column has numbers and they order like 1,10,11 instead of 1,2,3 etc.. When I try ch…
Hive: How do I INSERT data FROM a PARTITIONED table INTO a PARTITIONED table?
This is an extension of a previous question I asked: Is it possible to change an existing column’s metadata on an EXTERNAL table that is defined by an AVRO schema file? Question: In Hive 2.1.1, how do I INSERT data FROM a PARTITIONED table INTO a PARTITIONED table? What is the correct syntax? I have see…
Rewrite MS Access SQL statement to SQL Server
I wish to convert the following MS Access SQL statement to SQL Server. All of my attempts are resulting in different results from the old & original data. The new Query is: The problem caused by grouping date column in new statement, but in old one it is used in Last function to avoid grouping it and stil…
One if or multiple where?
Let’s say, I want to set a value to multiple rows depending on the value of another cell. So, I can make this in 2 ways: Select all items and set different values using IF: Update `table` set `a` = …
JSONB sort aggregation
I found this query that suits my needs thanks to this answer here in order to sort fields of data in a JSON document. (Fake, generated random data) SELECT jsonb_agg(elem) FROM ( SELECT * FROM …
Where clause in upsert conflict target
Suppose I have a table created like this: When attempting to insert a new row, there are three possibilties: No row for ‘name’ exists. The new row should be inserted. A row for ‘name’ exists that has a value of NULL. The existing row should be updated with the new value. A row for R…
SQL server query with multiple (same ID different date and different image) (filter by last date)
I want to fetch data from a huge db that same ID number each yea , but different photo for each date I want query to filter and show result with Last date including (ID and photo) to the given ID Answer Possibly the most efficient method is: For performance, you want an index on nid(id, date).
INSERT with autoincrement not working in SQL Server (with DB replication ?)
After no row deletion, but after getting the 60 existing rows by local subscription to replication from another SQL Server instance, I’m inserting new rows with: But this will fail since the ID will start over somewhere (9 in this case), instead of starting at the last ID used +1, ie., 61 in my case. Sy…