Skip to content

Tag: sql

MySQL put a specific row at the top of the result

I’m doing a basic SQL select query which returns a set of results. I want a specific row which the entry “Fee” to be put at the top of the results, then the rest. Something like: Can anyone help? Answer You could try this :

Using 2 “Group By” in one SQL Query

I got 3 tables that look like this: Locations: id,name Events: id,name,locationid Participants: id,name,eventid What I want is a query, that returns all locations, a count of the events linked to it and a count of the participants (indirectly) linked to a location. This is what I’m trying, but this quer…

How do I update a table with old value + the new value?

I have this SQL string which updates a row if it exists or creates a row if it does not, how do I do if it updates ctc_portfolio_coins_amount If I have a value of 100, or -100, how do I either substract it or add it to the current value when it updates? Table: Answer Arithmetic: The reference to ctc_portfolio…

Deleting Part of a string in HIVE

I am trying to delete a part of a string in HIVE. I want to delete the last eleven characters for all records in a column. The data looks like: 1018492743|0001-01-01 I want it to look like: 1018492743 The code I have tried looks like: Select right(a.ord_id, len(a.ord_id)-ll) It isn’t working because len…

How do I pull last 5 entry from a from a table through SQL query?

I have a table with data entry like below. I want to select the last 5 rows all the time when new data will be inserted. So, product_id 2-6 will be selected in here. But when I will enter a new product, id 3-7 will be selected and afterwards.. What will be SQL query for this? I am newbie. Any

How to prioritize result in laravel eloquent

I have a table with 4 columns. I want to display the row based on input and it should be able to display with priority according to the priority fields. example: My table looks like this: I have my test cases below how it should work: Now, I want to prioritize the result from title down to tags based in