I have a data about airline’s booking, using Oracle db, sample is structured as below: Recordlocator is booking code Sequencenmbr: whenever there is a change in booking, it records new status of a booking with higher Sequencenmbr. So the highest Sequencenmbr in the database shows the latest/current stat…
Tag: sql
Pivot Issue ORA-00918 column ambiguously defined
I am running the below query and need to output the rows as columns. When I am adding the second MAX statement, I am getting an error ORA-00918 column ambiguously defined. Not sure what I am doing wrong. Any help will be appreciated. Answer You probably need something like this I.e. 1) add alias to you pivot …
SQL MAX() function seems to truncate results
I have the following basic 3 Table Structure in mariadb/mysql. This simple SELECT returns incomplete records. I reduced the output of all follwing examples to a single dataset to avoid unnecessary clutter. The IP_LONG column is missing the follwing for example… My guess is, it has something to do with t…
Select ALL instead of ANY in a Many-to-Many relationship
Currently we have the following sample DB structure with a Many-to-Many relationship between lead and tag tables. Let’s imagine that we would like to perform the following queries. Give me all the leads that have ANY of the tags in a list. Give me all the leads that have ALL of the tags in the list For …
Why is my group by not grouping my values as expected?
My project is a clothes factory and I have 3 tables. Person : A table that contains people’s name Category : Contains each category of clothes in the factory (sockets, shoes, etc.) Quantity : The quantity of clothes for each person And I’m trying to display something like this : Name Quantity_shoe…
Php – cannot create new database record because primary key is null (autoincrement)
There are two tables: address and person. person_id (primary key, autoincrement) is a foreign key to address. I am trying to add an address record and person record from the same form but am getting this error. Uncaught Error: Attempt to assign property “person_id” on null in C:xampphtdocsappcontr…
Rewrite NVL and select statement according to string
I have a column, called parametre, which contains our parameters: So i want to get a output FA or DL, according to string PRIJEM_CISTY or PRIJEM_VRATKA: It works. But is there any “better” solution for this ? For example, decode() or RegExp() ? Answer You can put the two together to query
How to write just one query to divide result from 2 query?
I have a query in Entity Framework Core like below: I am dividing one currencyRate to another from 2 queries. There are 2 select queries. Only difference between queries is where condition. How to do this in one select query? Answer Pull both rows with Put an explicit order by on like Now you know the two row…
Recursive query compute parent values
I have 2 tables Persons and Sales. In Person there is relation between child and parent, I want to compute 20 percent of parent values with the following condition Persons Sales I want to get result like this I wrote this query but it does not give appropriate result Answer This should be a two steps algorith…
Grouping repeated numbers sqlite table
I have this table and I need the query to show the numbers repeated more than 2 times in which draw. I expect this result I’m doing this: But it doesn’t work. Thanks in advance. Answer You can first transpose your data with a cte and union, and then use group by: