two table EMPLOYEE and Department EMPLOYEE’s fields are ID,Name, Salary ,DEPT_ID(foreign key to department table) DEPARTMENT’S fields are id,NAME,LOCATION VALUES OF EMPLOYEE TABLE WILL Be Values OF DEPARTMENT TABLE WILL BE Output from these table should be DEPARTMENT_Name should be alpabetically w…
Tag: mysql
NEWID function causing error for prepared statement in MYSQL
I am trying to create a forgot password system, so I am using the NEWID() function to create a random code to be sent to the user’s email. I am using prepared statements to prevent SQL injections, but this still isn’t working: I am getting a warning on line two that the first parameter can’t…
Summing condition excludes rows without positive sum
I’m having a weird issue where in returning the sum of rows where a condition is true seems to only return rows if that condition is true – or at least, it is excluding a large majority of the rows that would otherwise be returned. Original query – which returns all rows: For each row that w…
MySQL ORDER BY FIELD for months
I have a table called months – this contains all 12 months of the calendar, the IDs correspond to the month number. I will be running a query to retrieve 2 or 3 sequential months from this table, e.g April & May June, July, August December & January However I want to ensure that whenever Decembe…
MySQL: retrieving the last record from each group and combining with the data of another table
There is a purchase table that information regarding the products bought. This will generate one one or more rows in the tStockMP table for each individual product bought. Now, I need to display the table information for each product in stock. Since the purchase table contains the history of the changes, that…
Error 1140 using the query builder of Laravel and count aggregate
I want to do the following SQL query using the Laravel query builder: I tried with the following code but it doesn’t work correctly: I reiceived the following error: Can help? Answer Aggregate functions like sum,count,min,max,avg when selected with other columns it must have a groupBy clause for one of …
Nodejs and SQL – Issue with inserting data to SQL using multiple select statements
Error image While inserting the data in SQL database table user_recipe_consumption by using multiple select statements i am facing error as – throw err; // Rethrow non-MySQL errors ^ Error: …
JOIN query and ANY query produced different results
I am new to SQL and I can’t figure out why the following two queries would have different results. The purpose is to list product names if there are any records in the order details table that quantity = 10. The first statement gives more results than the second one. I am using the “Northwind samp…
Can I update a SQL table based on data from another table, with unknown data? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I’m making a NetBeans Servlet which accesses a MySQL database; and updates data based …
Mysql – how to sort results by values in columns?
I have two database tables customers which contains data about customers with the scheme like that: mysql> SELECT * FROM customers; customer_id created_at partner_id 1 “…