Skip to content

Unexpected result in WHERE clause on AI ID field

I have a table which’s name is users in my MySQL database, and I am using this DB with Ruby on Rails application with ORM structure for years. The table has id field and this field is configured as AI (auto-increment), BIGINT. Example of my users table; The problem I am facing is when I execute the foll…

Query ORDER with UNION

I have to do punt an “*” in a list of dates, like this: So, with my low knowledge, I created something like this code: where “*” is present in the table Union. But, the command ORDER doesn’t work and I’ve a sort system just by number, like the follow: How can avoid this? Th…

Order By two columns but have one order

This question is sequelize specific but I’d figure if I found a way to do in SQL then I could find a way to do it in sequelize I need for the request to be ordered back by user.fullname which is joined by using include and by mockUser.fullname which is a JSON field. One important thing to keep in mind

Disregard duplicate rows only when these rows are contiguous

I am trying to show only the first occurrence of an activity if this activity occurs multiple times in a row. Thus, in the scenario below, if activity B occurs 3 times in a row, even if it is at different times, I want to only select the first occurrence. If it occurs again AFTER another activity I also want

INSERT INTO … VALUES () when not exists

I have insert: INSERT INTO barrier (barrier_id, usage_id, type_id, currency_id, modified_date, version_nr) VALUES (barrier_seq.nextval, (SELECT usage_id FROM usages …

Oracle PL/SQL ORA-00904: invalid identifier

I’m trying to declare a string and use it in a select statement but it’s throwing ORA-00904: invalid identifier. DECLARE var_laufi VARCHAR2(20) := ‘JEIV’; BEGIN EXECUTE IMMEDIATE q'[ WITH …

SQL – complex SELECT query to UPDATE

SQL noob here. So i have a table with a lot of products. Some of these products are clothing, meaning i have e.g. six different SKU’s for one product due to different sizes. I now want to set the …