Somewhere recently I read of a method to connect one SQL Server to another, so clients could connect and run queries that appeared to come only from the first server. I cannot remember the proper …
Tag: sql
How to concat all the entries of one column [SQL]
As the title states, with the following SQL query: I get the following result: Question: how to modify the query so that all the names are to be displayed in a row, so that they can be later used an array. What I tried: FOR XML, STUFF – doesn’t work Expected result: Answer If you are using SQL Ser…
SELECT rows with a new DISTINCT from a VARCHAR with CSV in it
I have an Oracle database table with a field called Classification which is VARCHAR. The VARCHAR is a CSV(using semi colons). Example: I want to pull all the rows with ONLY a different value in the CSV from the others. It is ok if a row has a previously found value as long as it has a new different value.
BigQuery SQL conditional IN
I have been trying to construct a conditional IN like below, but this gives me the scalar subquery produced more than one element error. How should I approach this type of query instead? The tables are not related. Answer Try this below- As your other tables are not related, you can try this below logic-
update a random row and get the row result back in MySQL
I have this table and an insert command is the following: The table contains random codes for each product_id. I want to get one unused code randomly (LIMIT 1 is ok for the job), mark the code as used and return it to the next layer. So far I did this: but this does not work well when multiple threads
Efficient way to handle below query? in SQLServer or PostgreSql (Self join)
I have an employee table as below I need to select employee_id, manager_id, result. result should have true or false depends on below conditions. If the employee is manager for someone then true If the employee has a manager then true I came up with a query, but I need to know if there are any other better wa…
Convert Postgre query to Hive/ Mysql
I have this table: I want to a situation where each footballer appears only once in a new table. For instance, Messi appears twice, but I want to take any occurrence of Messi in the new table. I am not sure how to convert it to either Hive or mysql. This is what I want the desired results to look
PostgreSQL. constraint allowing only one of many possible values
I have statuses like this: started,calculated,finished I need a constraint allowing only one NOT finished status in a table. This is allowed: this is forbidden due to two not finished statuses: Answer You can use a filtering unique index: The trick is to pass a fixed value instead of a column name to the on c…
Calling stored function in postgres 12 with json type argument by SQL query from pgAdmin results in error
I’m trying to call a stored function in postgres 12 DB which takes 1 parameter of json type and returns result of json type. The function is like this: The function must take a json with keys: “id” – for id of request sender, “token” – for it’s secret and “…
Get the immediate parent child relation in a table
I have a table with following value I need the output data from the above in the following format : Thanks in advance for any guidance on this. EDIT : I used the while loop approach to achieve this but trying to avoid the while loop. The while loop logic worked if proper sequence of ranklvl is there for a