mysql

How to store a dynamic List into MySQL column efficiently?

I want to store a list of numbers along with some other fields into MySQL. The number of elements in the list is dynamic (some time it could hold about 60 elements) Currently I'm storing the list into a column of varchar type and the following operations are done. e.g. aList = [1234122433,1352435632,2346433334,1234122464] At storing ...

Control decimal division precision in MySQLdb

MySQLdb does some weirdness where it seems to always return a Decimal object with 2 more significant figures than the numerator of a division operation. If the denominator is relatively large, this means that sometimes the result gets truncated to zero: >>> import MySQLdb >>> db = MySQLdb.connect(.....) >>> c = db.cursor(); >>> c.execu...

SSIS data Import from MySql

I am working with SSIS and trying to import data from MySql to SQL Server. I am having issues trying to convert mySql datetimes to SQL Server Datetimes. Any suggestions? ...

MySQL LIKE statement

Hi guys. I have a SQL query SELECT * FROM table WHERE column LIKE '%pdd%'. The problem is I need to get all results excluding those which start with "pdd", I mean find everything where "pdd" is not at the beginning. How could it be done? Thank you. UPD. Sorry, I should've clarified my question a little bit more. I do need to match "p...

MySQL GROUP BY date when using datetime

In MySQL, let's say I have a table with a column called 'actionTime' declared as a 'datetime' (YYYY-MM-DD HH:MM:SS). Is there an easy way to use "GROUP BY actionTime" but only use the 'date' part of the 'datetime'? Thanks ...

Return value 1 on FIRST INSTANCE of unique

I have a table with Name and Area. I want to run a query that returns that table with the addition of a 'Special_COUNT' The count returns 1 on the firstmost Concat(Distinct(Name,Area); should return 0 otherwise For example: Name | Area | Special_COUNT | ABCD | US | ...

PHP Try and Catch for SQL Insert

I have a page on my website (high traffic) that does an insert on every page load. I am curious of the fastest and safest way to (catch an error) and continue if the system is not able to do the insert into MySQL. Should I use try/catch or die or something else. I want to make sure the insert happens but if for some reason it can't I ...

SQL query in MySQL using GROUP BY

Okay so this query should be easy but I'm having a bit of difficult. Let's say I have a table called 'foo' with columns 'a', 'b'. I'm trying to figure out the following in one query: select how of column 'a' are available of type column 'b', this is done with the following: mysql> select count(a),b from foo GROUP BY b; that's straigh...

Select newest entry from a joined MySQL table

I have stock quantity information in my database. 1 table, "stock", holds the productid (sku) along with the quantity and the filename from where it came. The other table, "stockfile", contains all the processed filenames along with dates. Now I need to get all the products with their latest stock quantity values. This gives me ALL th...

Simple Math max function in MySQL

How to find the maximum of two explicit values in MySQL? Something like MAXIMUM(1, @foo). There are group functions like MAX, MIN, AVG, etc that take column name as an argument and work with result sets. Is it possible to convert two explicit values to a result set and use those functions? Some other ways? P.S.: I need a max function f...

Dealing with ugly SQL in Java

Here goes a SQL-Java coding style question... How do others here deal with creating complex custom queries in Java cleanly? I am speaking of the seemingly simple task of preparing a string which is the SQL statement to be executed. I am aware of HQL, and also of stored procedures, but honestly I don't really love these solutions. Perh...

Null Foreign Key

Hello, newbie programmer here. I have 3 tables namely product, category, and subcategory. I configured their relationships this way: Product to Category: Many-to-many Product to Subcategory: One-to-one Subcategory to Category: Many-to-one I added a subcategory_id column which is a foreign key in the product table (for mapping the prod...

mysql Query: Select Lastest Where Another Row With N doesn't exist

Hi, sorry about the title, I'm not sure how to even describe this, which makes it even harder to search for a solution. I have a table which has many answers: CREATE TABLE `answers` ( `a_id` int(11) NOT NULL auto_increment, `p_id` int(11) NOT NULL default '0', `q_id` int(11) NOT NULL default '0', `user_id` int(11) NOT NULL defa...

Mysql with Asp.net

Can anyone help me to clarify that how to connect mysql server with asp.net and all the relevant query command like select,insert etc. regards shashi ...

MySQL: what data type should I use for a string of comma separated values?

I need to store a string of comma separated values. '1,23,47' or '1' or '' (null) What data type would work best for comma separated values? Note: I am only asking which data type would be appropriate for this scenario. ...

MySql Performance Question: MD5(value)

Hi, for security purpose I do some queries in this way: SELECT avatar_data FROM users WHERE MD5(ID) ='md5value' So, for example I have this entries: -TABLE.users- ID | avatar_data 39 | some-data I do this query: SELECT avatar_data FROM users WHERE MD5(ID) ='d67d8ab4f4c10bf22aa353e27879133c' 'd67d8ab4f4c10bf22aa353e27879133c' is ...

Automatically add user and date to records

Hello guys, I have a database which can be accessed by multiple users. Is there any way I can set the tables such that whenever somebody enters a new record or modifies a record, his/her username and the date entered is stored into 2 columns in the same table as the record itself. The table would look like this: Id | Name | Username...

Compare unique values from two mysql tables

I have two mysql tables: TableA has 10,000 records TableB has 2,000 records. I want to copy the 8,000 unique records from TableA into TableB ignoring the 2,000 in TableB which have already been copied. ...

stored procedure cursor mysql 5.1

Below cursor declaration works with 5.0 but not with 5.1. DECLARE CUR_GBLVAR CURSOR FOR SHOW GLOBAL VARIABLES; ...

Tornado Web Framework Mysql connection handling

I have recently been exploring the Tornado web framework to serve a lot of consistent connections by lots of different clients. I have a request handler that basically takes an RSA encrypted string and decrypts it. The decrypted text is an XML string that gets parsed by a SAX document handler that I have written. Everything works perf...