Table 1 ID FirstName LastNmae city Group code 11 john smith abc E P 21 don davis def E P 3 vee miller ghi Q P 6 vee miller ghi Q P Table 2 ID FirstName LastNmae city Status EmpName Phone 11 john smith abc U Company 1 123 21 don davis def P Company 2 456 3 vee miller
Tag: mysql
MySQL error: Cannot add foreign key constraint (PrestaShop module)
I’m trying to write MySQL queries for my custom PrestaShop module. I encountered an issue while adding foreign keys and have no idea what might be wrong. I double checked column types and their existance. Here’s the error: Cannot add foreign key constraint And here is all the code I’m trying to run during installation The queries execute perfectly without
Return records of one value and not in other values
Apologies for asking such simple question but here I am getting trouble while getting records from single table, my table contains records which have different values in prod_code for similar product_number. I want records of such product_number which have specific prod_code, and not others. For example from below table I need a records which have only prod_code with value CIOFB1
MYSQL: Can’t update table in stored function/trigger
I have a table called “report” I am trying to create a trigger for in case insert a state with value “failed” for the ip_element “10.66.16.55” and path “/dev/map/4-4”, the state change to “ok” I get the next error: Answer You cannot update the table on which you have a trigger (as the error message states). Instead, you have to
How I fetch values from one column based on distinct values from other column?
I have two columns in a table and I want a query to fetch First column values based on distinct values from Second column. Since, There are multiple combinations of First and second column I would like to have the first match from each combination. DATASET: First Column Second Column A abc B abc C abc D abc F abc
Create a new record for every user in a database based on a column
I have a MySQL database with a user table, after a new requirement I had to create a new table called social_media and from now on every new user will be created with a social_media_id column that holds a reference to their social media. I want to update my database so that every user that didn’t had a social media
Creating and using an SQL variable after some set text
I’m needing to set some text into a field within a row, and use a SQL variable as part of that text. I’m then using this sql statement in a bash script. I have I believe I created the variable correctly I then need to use this variable as follows However its not working and is giving me errors about
MySQL procedure not working with both select and delete
I created a procedure to get a vehicle id from the vehicle table using vehicle number input, then delete the booking record for that vehicle id, and at last to delete the entry in the vehicle table… But when creating the procedure I get an error at line 7 saying Error Code: 1064. You have an error in your SQL
Null values affecting case logic
I am having a problem in the following query. In the AR column there are some null values due to the left join of the wbr_global.raw_station_extended_attribute. To fix this I added a case to default to 0 if it is null. The issue this is causing is in my next case statement for assinging a station size. All the null
SQL – How to calculate product discount and get products where discount is greater than 25?
I want to calculate discount in SQL query and want to get products having discount greater than 25. I am trying with following query. Please correct me what i am doing wrong. Thank you I am getting following error. #1054 – Unknown column ‘p_discont’ in ‘where clause’ Answer use inline condition in where clause