I want to dynamically add another column hook_name, via an SQL select query, based on a condition. For example if hook_type = 0, table hook_name should have a value of OFFER, and similarly for hook_type = 1, hook_name should show “ACCEPT”. Below is a screenshot of the result: The select query is this: Thanks in advance. Answer Use a Standard
Tag: mysql
Sum columns depending on another column value
I’m having trouble with summing the fields values based on another fields value. I need to SUM(activities.points) based on activities.activity_type if it’s used_points or added_points and put it in AS used_points/added_points. Table activities: Table subscriptions: What I need: What I tried : Which is wrong. Thanks Answer You want to use SUM(IF( )). You want to add up the values
MySQL select formatted date from millisecond field
I have a column in a MySQL database that contains a date as milliseconds (epoch). I want to build an SQL query that formats the date as something human readable (day, month, year, hours, minutes, …
Generate CREATE statements for all MySql Tables
I want All CREATE statements of MySql Tables in 1 query result. For example, INFORMATION_SCHEMA contains all table names,comments etc. but where are the CREATE statements are stored in MySql ? can it be retrieved in one query for all tables ? Currently i am retrieving TABLE ddl as below for 1 table. I have 100’s of tables so i
Foreign Key constraints missing after phpmyadmin export
I create a table in mysql using the following script: When I export the created table from phpMyAdmin, I obtain the following script So the question are: where is my foreign key constraints? does KEY refer to FK? Seems that the two tables utente and attivita are no longer referenced in the new generated script. where am I doing wrong?
MySQL WHERE with conditions/priority condtion
This one is a weird one that I just can’t seem to wrap my head around. Basically I need to search based on a value that has an override. So there are 2 columns with essentially the same content. One …
SQL auto_increment behaviour
My first question is: Can I manually input ID into an auto_increment column of a table? For example: I have 10 records with ID from 1 to 10. Can I manually input the 11 record with the ID of 3 (yes, it’s a duplication!) My second question is: I assume that it’s possible to manually input ID number, what if
What does the ( ‘ > ) symbol mean in the command line in MySQL?
I’m new to sql and for some reason, the arrow symbol ( -> ) that I am used to seeing in teh command line, which mean it is ready for input, is now displayed as ( ‘> ) and it does not accept commands. What does it mean and how do I get back to ( -> ) ? Thanks
Using COUNT in GROUP_CONCAT
This is my table: id | fk_company ——————- 1 | 2 2 | 2 3 | 2 4 | 4 5 | 4 6 | 11 7 | 11 8 | 11 …
Conditional UPDATE in MySQL
I am trying to UPDATE values from a table, but I need to add some conditions. I found the function CASE, but I am not if it is the best method. Here is an example. My table is ‘relation’: userid1 | userid2 | name1 | name2 I got for example: Output: 4 | 3 | bill | jack and I