Sample Data: Desire Data: how to write a sql to update the room seat number to serial num in MySQL 5.7? the room’s seat is from 2-20. Answer One option uses the update/join syntax. In MySQL 5.7, where window functions are not available, you can emulate row_number() with a correlated subquery (which is s…
Tag: sql
How to calculate running sum for each group in MySQL
Straightforward summation I can do with sum() function. But I’ve a different situation here. I’ve a table Student with only 2 fields. For instance just assume that there is only 1 student in the entire class: And I have his scores for the days when exams were taken with one more column in the runt…
SQL query to run LDAP query to return AD listing of active users and then groups they are assigned to that start with GRP-XP%
I am trying to write a sql statement to control a report header selection of multiple database by user groups a user is assigned to. This is to limit the database selection security when running an SSRS report so that they can’ only select their branch or group of branches they have access to. So far I …
Subquery with joins – need help returning rows even if empty – MySQL
okay guys, this is a big one that’s confusing as hell. I’m creating a forum type dealio: I have an array of Topics and each topic has an array of Posts associated with the Topic. The Topics list page should show the latest Post from that specific Topic. (Each topic is in a category as well) Topic Latest post …
How to update row by id using case?
Is it possible to update by id other row values? I try like this But nothig.. UPDATE era SET id = CASE WHEN id = 3 THEN gender = ‘Female’–or maybe it is possible to call insert command here? …
can i use md5 hashed values inside $this->db->escape() in codeigniter,
when i tried to use md5 hashed values inside $this->db->escape() i’m getting error like below when i tried to fetch count of results “Call to a member function num_rows() on bool” my code Answer You are making double escape as i see it. Remove the single quotes from $this->db->es…
get users that did not buy a product
I have three tables users table +————————–+————–+——+—–+———+—————-+ | Field | Type | Null | Key | Default | Extra | …
Are SQL Server unique constraints “Silent” or do they raise an exception?
I want to prevent inserting duplicate values into my tables. At first, I added code to check if the value already existed in the database, but that seems like a lot of overhead / wasted time if I can prevent it at the DDL level. So I found this and changed one of my tables (as an example) from this:
Update query without condition but need to update 90% of records in a table – SQL / SnowFlake
Update query without a condition but need to update a certain percentage of rows in the table for a specific column. Say I have 100 rows in a table, I want update a specific column based but no specific condition; just that 90% of the records in the table has to have this new value that I want to update.
Is there a way to dynamically execute queries in SQL without using user defined function?
I am currently working on the table containing some documents data, focusing on the columns containing date of document and net income. What I have to do is to write an sql statement which will result …