I have two tables linked through a many-to-any relationship. Table one contains all voters with an ID, table two contains all elections with an ID, and table three links both tables using their IDs. …
Tag: mysql
Using case statement or IF inside a WHERE clause
I have several stored procedures that are almost identical but have some different AND parts inside a WHERE clause. Based on a variable deptname, I want to add additional AND/OR conditions to my already existing WHERE clause. So kind of like IF/CASE WHEN on the part that is different. Think about it as string concatenation What is the appropriate way
query mysql to find total value
please help me. imagine the table as bellow and I want to query and show result like this I dont know how to write query to show result like that. I used (date_join) as dates, count(id) and group by date(date_join) and the result not show like that. Answer In MySQL 8.0, you can solve this with aggregation and a window
query for join two column and get one row per left with column that have array of right table refrenced to left table row
hellow.I have a tablt product like this +——-+——-+ | id | name | +——-+——-+ +——-+——-+ | 1 | shirt | +——-+——-+ color table like below: +——-+——–+ | id …
SQL Lag() to Find Datetime Difference
I am trying to find the difference between Datetime entries in my sql table and was following this article – https://blog.jooq.org/2015/05/12/use-this-neat-window-function-trick-to-calculate-time-…
JSON_CONTAINS for multiple attributes on object in array?
Currently using MYSQL 5.7, soon to be migrating to 8.0. We have a json field in our database which has values which look like this: [ { “first_name”:”bob”, “last_name”:”lisserman” }, {…
How to design tables with foreign key but value is NULL in MYSQL?
I am trying to design a database with 2 tables. Project and Student. Student table records what project each student selects, and the student could only select a project that exists in the project table. However, when a student first enrolls in the class, I want to insert his info into the student table but at that time, he did
get first row fo each group SQL
I have data like below. I would like to get the top choice for each gender from the following data I have tried mapping the choices by descending order as below : BUT, I would like to get the following table where i get the top choice for eachgender : Answer If you are runing MySQL 8.0, you can use
How to search for multiple words with one query?
I am trying to make a simple php search using the following query. This works perfectly however the query only gives results for the first word. Would there be a way to get a combined result for all …
how get random questions from database include Categories?
Hallo i try to make a simple quiz application in php based on math tests from many years. I have database with such columns: -id -pytanie -a -b -c -d -poprawna -rok_id -typ_id I use rand function to get random id and next i use this in sql answer to get random question. However id dont know how get radnom