mysql

MySQL all unique values from 2 or more columns

I'm trying to select UNIQUE values from a non-uniformized table and show only the unique ones. SELECT DISTINCT "year" as sorter, year(data) as year, NULL as location FROM site WHERE tipo='projects' UNION SELECT DISTINCT "loc" as sorter, NULL as year, spare_1 as location FROM site WHERE tipo='projects' ORDER BY sorter ASC, year DESC...

Sum until certain point from each group - mysql

Hello, I have a MySQL table with about 1000 rows, filled with different types of fruit trees and their locations on a farm. The data looks like this: Fruit Trees Location on Farm 7 | 6 | G G 5 | G Y 4 | G G 3 | A X G G 2 | A A A 1 |_ _ _ _ _ _ _ 1 2 3 4 5 6 7 X Fruit Trees MySQL Tab...

Selecting WHERE date is greater than current date

I have the following query: SELECT id FROM auctions WHERE end_dt > TIME_TO_SEC(TIMEDIFF(end_dt, now())) > '0' GROUP BY auctions.id ORDER BY end_dt ASC LIMIT 15 This is really slow. But basically, we're trying to select the most recent 15 records that are about to "end" by checking if the amount of seconds left is greater than zero. ...

Remote backup of MySQL database

Our Java server application logs data to a SQL database, which may or may not be on the same machine. Currently we use MS SQL Server, and we're now porting to MySQL. A user configures database backup parameters on our app server, e.g. time of day to run a backup, and the app server executes SQL Server's BACKUP DATABASE command at the app...

Update database without reloading page

Ive just had some fantastic help from Sandeepan, thank you! Please can anyone see what I have done wrong with this .... <head> <script type="text/javascript" src="jquery-1.4.2.js"></script> <script type="text/javasript"> function addItemToUsersList(itemId) { $.ajax({ 'url': 'member-bucketadd-execTEST.php', 'type': 'GET...

MySQL scheduling an event.

I tried with this syntax but it never transferred the data. CREATE EVENT event_test1 ON SCHEDULE EVERY 1 MINUTE STARTS '2010-09-02 15:19:25' ON COMPLETION NOT PRESERVE ENABLE DO insert into schema2.table1 (ID) select ID from schema1.table1 Limit 1000 I don't see the o/p in the table1 of schema2, what did i miss? ...

Mysql Connector .Net is taking more than 40 mins to update database model

Hello Everyone, I am using MySql Connector 6.2.3 with Visual Studio 2008 and i have a database with 119 tables, which is constantly growing. When i want to update the entity framework model "Update Model from Database" option from visual studio it is taking more than 40 mins to update, that is killing my productivity. Is this happening...

mysqli giving "Commands out of sync" error - why?

I am trying to run the following. <?php $db = mysqli_connect("localhost","user","pw") or die("Database error"); mysqli_select_db($db, "database"); $agtid = $_POST['level']; $sql = sprintf("call agent_hier(%d)", $agtid); $result = mysqli_query($db, $sql) or exit(mysqli_error($db)); if ($result) { echo "<table border='1'> ...

Event scheduler in mysql

Create EVENT event_test_name ON SCHEDULE EVERY 1 MINUTE STARTS '2010-09-02 12:10:15' ON COMPLETION NOT PRESERVE ENABLE DO SET Total=-1; SET Total = (SELECT COUNT(0) FROM schema1.table1); SELECT Total; IF Total >50000 THEN insert into schema2.table1 (column1) select schema1.table1.column1 from schema1.table1; end if; This is the eve...

PDO: Connecting to different machine, 'Can't connect through socket' Error

I'm trying to connect to a different machine: $this->_connection = new PDO("mysql: host=MYSQL_SERVER; dbname=MYSQL_DATABASE",MYSQL_USER, MYSQL_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); But PDO barfs: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) ...

Best way to migrate a MySQL table with dupes to another table with a UNIQUE constraint

I am trying to work out the best approach for a data migration. I am migrating some data (~8000 rows) from a table like this: CREATE TABLE location ( location_id INT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY, addr VARCHAR(1000) NOT NULL, longitude FLOAT(11), latitude FLOAT(11) ) Engine = InnoDB, DEFAULT CHARSET=UTF8; ...

MySQL unicode literals

I want to insert a record into MySQL that has a non-ASCII Unicode character, but I'm on a terminal that doesn't let me easily type non-ASCII characters. How do I escape a Unicode literal in MySQL's SQL syntax? ...

MySQL create "before insert" trigger failing and raising errors in triggers

I have successfully created an insert before trigger on a table using the innodb engine which "throws" an error by performing an insert on a non-existent table. The problem is that as I try to run the database create script on the production server it fails because the insert table does not exist. However, the same script runs fine on my...

How do I specify a mysql cascade rule for the following...

In mysql, I've got the following: TABLE docs ( ID title content ) TABLE specialDocs ( docID -> docs(ID) userID -> users(ID) ) So specialDocs is a subset of documents that can belong to users. I am wondering: Is it possible to specify a cascade rule so that when a user is deleted, the docs that belong to that use...

MYSQL How to use trim in select query

my table have set of records around 50, in the table i have column called USERNAME , but some of username leading and trailing have the white space , so am not getting exact order result because of white space, So tell me how to use the trim in SELECT query , Thanks ...

Proper datastructure for the following...

I want to represent documents in a database. There are several different types of documents. All documents have certain things in common, but not all documents are the same. For example, let's say I have a basic table for documents... TABLE docs ( ID title content ) Now let's say I have a subset of documents that can ...

MySQL connector EF stored procedure

I have the following stored procedure: CREATE PROCEDURE GetSequenceNextValue(IN sequenceName VarChar(100)) BEGIN UPDATE Sequences Set currentValue = LAST_INSERT_ID(CurrentValue + 1) WHERE name = sequenceName SELECT LAST_INSERT_ID(); END But when I update my model, this procedure is not imported even into storage model. ...

SQL Server minus MySQL Features

Hi, I know MySQL and and trying to learn SQL Server . I am looking for features/keywords that are in SQL Server and not in MySQL. Eg: TOP, CLUSTERED/NONCLUSTERED Indexes etc.. Any links/pointers are appreciated. Thanks! ...

How to select records one by one without repeating

select id, name from customer order by random() limit 5; The above query select random records. However it repeats rows. I just want to select a single row each time without repeating. Say i have id 1 to 5. For first time i want to select 1, second time the query displays 2 then 3,4 & 5. Once the sequence is completed it starts again w...

Flex w/ AMF Returning results slowly.

I think this is just a matter of fine tuning some different elements, but I'd like to know your take. I've got a Flex app, using the Flex 4 data services, communicating with Zend AMF services. One of the services returns all the results in a database using SELECT * FROM table there are ~1200 rows (140KB package size). My problem is the ...