Tag: mysql

SQL Query with unknown number of columns

I’ve written a query on a table which contains a list of ‘Statements’ against ‘Companies’ like so (obviously simplified): Statement | Company ————————— ABC | CompA ABC | CompB DEF | CompC The query presents the information like so: Statement | CompA | CompB | Comp C ————————————– ABC | X | X | DEF […]

Update sum of records

I have this table called ‘bill’ as shown below: Cust_id |Bill_amt |Brand |Skincare |Toner |BrandA |BrandB |A_skincare |A_toner |B_skincare |B_toner 001 |100 |A |50 |50 |NULL |NULL |NULL |NULL |NULL |NULL 001 |200 |A |150 |50 |NULL |NULL |NULL |NULL |NULL |NULL 001 |500 |B |355 |145 |NULL |NULL |NULL |NULL |NULL |NULL 009 |325 […]

Should the Supplier, Client and User tables be combined

I currently have 3 table and I am unsure if they should be merged or not. They do have similar fields, and a supplier would need to login at some point or another, and even clients User Username Password Name Surname Mobile Telephone Email Client Name Telephone Email Fax VatNo Supplier Name Telephone Email Fax […]

MYSQL duplicate key syntax using multiple primary keys

Hello everyone this is my first post, so please be forgiving. I have searched SO for these questions and while they come close to an answer what I have seen has not been correct. Environment info: MySQL Server version: 5.1.69-community-log MySQL Community Server (GPL) Kernel version: CentOS release 5.10 (Final) I am working on a […]

SQL Query for Data Copy to Other Field

i have use a db for my school records and update them every month like inspection data for every month observed performance for students. my question is… i have enrollment table as per my school register Class: Cls_1,Cls_2,Cls_3,… Enrolled Students 30 40 50 … Present Students 10 20 30 … So, i want (Column) cls_1 […]

MySQL import data from SQL Server export file

I need to import into a MySQL database some data that has previously been exported from a SQL Server 2008 database. The SQL Server export has been made into a SQL file, and export file format looks like this: INSERT [table1] ([column1], [column2], [column3]) VALUES (1351801, 1548565, N’/******************************************************************************* * *******************************************************************************/ package chap1; public class Main […]

sum sql group by values from another table

I’ve got 2 tables: Online Orders, Online orders details I have an issue on how to calculate the total amount of the order in Online Order table based on the detail order table. The detail table looks like: id_order Id_product quantity price value 1 2 1 3 3 1 3 2 2 4 2 1 […]

How can I prevent SQL injection in PHP?

If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example: $unsafe_variable = $_POST[‘user_input’]; mysql_query(“INSERT INTO `table` (`column`) VALUES (‘$unsafe_variable’)”); That’s because the user can input something like value’); DROP TABLE table;–, and the query becomes: INSERT INTO `table` (`column`) VALUES(‘value’); DROP […]

PHP PDO connection with MS SQL Server using ODBC

I have a db.php file & and init.php to use within my register.php file. I have a database within MS SQL Server and am trying to connect to it using PDO. This error is showing and I can’t see why. I used the same code to connect to a MySQL db and this inserted the […]

Java JDBC MySQL connection error: ClassNotFoundException

im trying to connect to the database but im getting this error. this is the code import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; public class JDBCInsertValues { public static void main(String[] args) throws Exception { Class.forName(“com.mysqljdbc.Driver”); Connection conn = DriverManager.getConnection( “jdbc:mysql://localhost:3306/Drivers”); PreparedStatement statement = conn.prepareStatement(“SELECT * […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.