I want to make a query which will add a column depending of what condition is meet(I have tried with sequelize without obtaining the result that I wanted) therefore I want to try with plain SQL because It does not have as many limitations. EXAMPLE: SELECT * FROM db.messages WHERE user_id = userID OR $contacts…
Tag: mysql
MySQL tree structure
Hello i am trying to prepare tree structure with MySql, tables look something like this. My Question is: Is it possible to do left join and sort columns by name, but if in lang is eq to “fra” return that row with that name, otherwise return “eng” name. Pseudo code So final result will …
How to display the total count of the last row by filestatus?
I have to display the total count of the last row by filestatus. tbl_bankdata tbl_fileStatus I have two tables tbl_bankdata and tbl_fileStatus. I am sending bank_id in the tbl_fileStatus as a f_bank_id. Now I have to show the last f_bankid count. For example, I have to fetch the count where f_filestatus=1. so…
MYSQL select name from id [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question I need to get the name from the author id in table post. I have these 2 tab…
MySQL – Performance issue while joining most recent
I have two tables, markets (27 records) and histories (~1.75M records, ~67K per market). I need to get every market with its most recent histories record. The solutions I tried work but are incredibly slow. Tables DDL What I tried 1 – Uncorrelated subquery I started with this solution since I used it ot…
Access Values from a customer table to a room type table
I’m Stuck in the middle of my MySQL project. Basically for now I have three tables Room_Type, Room, Customer. Read my code for Room_Type Table and in Room Table, there’s a foreign key through which I can access its room_type (Standard, deluxe, etc) and in the customer table, there’s a foreig…
Selecting first and last time stamps of a section
I have a MySQL database with a table like: I would like to select from this table the first and last timestamp for each value of each Batch_Number. I would like the table to look like: I am not sure how to select both, when the previous Batch_Num is different from the curent one, and also when the next one
SQL: Add multiple where clauses in a single query
I want to run an SQL query from Node.js. I am currently showing the total number of projects that have a specific status in each of the 4 quarters. What I want to do now is show the same result but while adding one more condition i.e, Fiscal Year. Here’s my code for the 4 quarters: This prints output in
Query only doing half of what I want
I have a function that is supposed to delete a product and, with it, delete its stock as well. But it keeps just deleting the stock. SSometimes I change the order of the querys and it shows an error that I can’t delete idproduto because its an FK, so I put the delete stock query first. It deletes the st…
Query items from a history table
I have a “library” history table (Excel like) to see where a book was or is. id date book action client 1 2020-12-01 1 toClient 1 2 2020-12-02 1 returned 1 3 2020-12-03 1 toClient 2 4 2020-12-04 2 toClient 2 5 2020-12-05 3 toClient 1 6 2020-12-06 3 returned 1 7 2020-12-07 2 returned 2 8 2020-12-08…