Search Results

Search found 36111 results on 1445 pages for 'mysql update'.

Page 31/1445 | < Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >

  • MYSQL stored function - create function (function definition) problem using FORMAT

    - by Jason Fonseca
    Hi all, I keep receiving an error with the following code. I am trying to make a function that will format a field (content=0.0032) into a varchar/percent (content=0.32%). At the moment i'm just trying to get format to work, and it throws up an error "Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'len);" The function definition for "Format" is "Format(X,d)" where x is the number and d is the number of decimal places to round too. It then should output a string ###,###,###.## etc. My code is as follows: DROP FUNCTION IF EXISTS percent; DELIMITER $$ CREATE /*[DEFINER = { user | CURRENT_USER }]*/ FUNCTION `auau7859_aba`.`percent`(num DOUBLE, len INT) RETURNS VARCHAR(10) DETERMINISTIC BEGIN RETURN FORMAT(num,len); END$$ DELIMITER ; Save me...Luke

    Read the article

  • Synchronize model in MySQL Workbench

    - by Álvaro G. Vicario
    After reading the documentation for MySQL Workbench I got the impression that it's possible to alter a database in the server (e.g. add a new column) and later incorporate the DDL changes into your EER diagram. At least, it has a Synchronize Model option in the Database menu. I found it a nice feature because I could use a graphic modelling tool without becoming its prisoner. In practice, when I run such tool I'm offered these options: Model Update Source ================ ====== ====== my_database_name --> ! N/A my_table_name --> ! N/A N/A --> ! my_database_name N/A --> ! my_table_name I can't really understand it, but leaving it as is I basically get: DROP SCHEMA my_database_name CREATE SCHEMA my_database_name CREATE TABLE my_table_name This is dump of the model that overwrites all remote changes in my_table_name. Am I misunderstanding the feature?

    Read the article

  • Filtering MySQL query result according to a interval of timestamp

    - by celalo
    Let's say I have a very large MySQL table with a timestamp field. So I want to filter out some of the results not to have too many rows because I am going to print them. Let's say the timestamps are increasing as the number of rows increase and they are like every one minute on average. (Does not necessarily to be exactly once every minute, ex: 2010-06-07 03:55:14, 2010-06-07 03:56:23, 2010-06-07 03:57:01, 2010-06-07 03:57:51, 2010-06-07 03:59:21 ...) As I mentioned earlier I want to filter out some of the records, I do not have specific rule to do that, but I was thinking to filter out the rows according to the timestamp interval. After I achieve filtering I want to have a result set which has a certain amount of minutes between timestamps on average (ex: 2010-06-07 03:20:14, 2010-06-07 03:29:23, 2010-06-07 03:38:01, 2010-06-07 03:49:51, 2010-06-07 03:59:21 ...) Last but not least, the operation should not take incredible amount of time, I need this functionality to be almost fast as a normal select operation. Do you have any suggestions?

    Read the article

  • how to delete duplicates in mysql using case

    - by JPro
    Right now I am using something like this to delete duplicates in mysql table : delete t2 from my_table1 as t1, my_table1 as t2 where t1.TestCase = t2.TestCase and t2.id > t1.id; say I have a structure like this : ID TestCAse Result 1 T1 PASS 2 T2 FAIL 3 T3 FAIL 4 T3 PASS now, in the above case T3 is duplicate entry, and if I use the SQL that I mentioned above, it would delete 4th row where the result is PASS, but this is the row that I want to keep and I want row 3 to get deleted which is FAIL. Any help please? Thank you.

    Read the article

  • Can MySQL Nested Select return list of results

    - by John
    Hi I want to write a mysql statement which will return a list of results from one table along with a comma separated list of field from another table. I think an example might better explain it Table 1 ======================== id First_Name Surname ---------------------- 1 Joe Bloggs 2 Mike Smith 3 Jane Doe Table 2 ======================== id Person_Id Job_id --------------------- 1 1 1 2 1 2 3 2 2 4 3 3 5 3 4 I want to return a list of people with a comma separated list of job_ids. So my result set would be id First_Name Surname job_id ------------------------------ 1 Joe Bloggs 1,2 2 Mike Smith 2 3 Jane Doe 3,4 I guess the sql would be something like select id, First_Name, Surname, (SELECT job_id FROM Table 2) as job_id from Table 1 but obviously this does not work so need to change the '(SELECT job_id FROM Table 2) as job_id' part. Hope this makes sense Thanks John

    Read the article

  • Indexing only one MySQL column value

    - by BrainCore
    I have a MySQL InnoDB table with a status column. The status can be 'done' or 'processing'. As the table grows, at most .1% of the status values will be 'processing,' whereas the other 99.9% of the values will be 'done.' This seems like a great candidate for an index due to the high selectivity for 'processing' (though not for 'done'). Is it possible to create an index for the status column that only indexes the value 'processing'? I do not want the index to waste an enormous amount of space indexing 'done.'

    Read the article

  • mysql select from a table depending on in which table the data is in

    - by user253530
    I have 3 tables holding products for a restaurant. Products that reside in the bar, food and ingredients. I use php and mysql. I have another table that holds information about the orders that have been made so far. There are 2 fields, the most important ones, that hold information about the id of the product and the type (from the bar, from the kitchen or from the ingredients). I was thinking to write the sql query like below to use either the table for bar products, kitchen or ingredients but it doesn't work. Basically the second table on join must be either "bar", "produse" or "stoc". SELECT K.nume, COUNT(K.cantitate) as cantitate, SUM(K.pret) as pret, P.nume as NumeProduse FROM `clienti_fideli` as K JOIN if(P.tip,bar,produse) AS P ON K.produs = P.id_prod WHERE K.masa=18 and K.nume LIKE 'livrari-la-domiciliu' GROUP BY NumeProduse

    Read the article

  • [MYSQL] Select users who own both a dog and a cat

    - by matte
    Hi, I have this sample table: CREATE TABLE `dummy` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userId` int(11) NOT NULL, `pet` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; INSERT INTO `dummy` (`id`, `userId`, `pet`) VALUES(1, 1, 'dog'); INSERT INTO `dummy` (`id`, `userId`, `pet`) VALUES(2, 1, 'cat'); INSERT INTO `dummy` (`id`, `userId`, `pet`) VALUES(3, 2, 'dog'); INSERT INTO `dummy` (`id`, `userId`, `pet`) VALUES(4, 2, 'cat'); INSERT INTO `dummy` (`id`, `userId`, `pet`) VALUES(5, 3, 'cat'); INSERT INTO `dummy` (`id`, `userId`, `pet`) VALUES(6, 4, 'dog'); How can I write the statements below in mysql: Retrieve all users who own both a dog and a cat Retrieve all users who own a dog or a cat Retrieve all users who own only a cat Retrieve all users who doesn't own a cat Thanks!

    Read the article

  • using check contraint in MySQL for controlling string length not working

    - by ptrn
    Dear stackoverflow, I'm tumbled with a problem! I've set up my first check constraint using MySQL, but unfortunately I'm having a problem. When inserting a row that should fail the test, the row is inserted anyway. The structure: CREATE TABLE user ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, uname VARCHAR(10) NOT NULL, fname VARCHAR(50) NOT NULL, lname VARCHAR(50) NOT NULL, mail VARCHAR(50) NOT NULL, PRIMARY KEY (id), CHECK (LENGTH(fname) > 3) ); The insert statement: INSERT INTO user VALUES (null, 'user', 'Fname', 'Lname', '[email protected]'); I'm pretty sure I'm missing something basic here.

    Read the article

  • MySQL - Sort on a calculated value based on two dates

    - by Petter Magnusson
    I have the following problem that needs to be solved in a MySQL query: Fields info - textfield date1 - a date field date2 - a date field offset1 - a text field with a number in the first two positions, example "10-High" offset2 - a text field with a number in the first two positions, example "10-High" I need to sort the records by the calculated "sortvalue" based on the current date (today): If today=date2 then sortvalue=offset1*10+offset2*5+1000 else sortvalue=offset1*10+offset2*5 I have quite good understanding of basic SQL with joins etc, but this I am not even sure if its possible...if it helps I could perhaps live with a single formula giving the same sort of effect as the IFs do....ie. before date1 = low value, after date2 = high value... Rgds PM

    Read the article

  • Searching a table MySQL & PHP.

    - by S1syphus
    I want to be able to search through a MySQL table using values from a search string, from the url and display the results as an XML output. I think I have got the formatting and declaring the variables from the search string down. The issue I have is searching the entire table, I've looked over SO for previous answers, and they all seem to have to declare each column in the table to search through. So for example my database layout is as follows: **filesindex** -filename -creation -length -wall -playlocation First of all would the following be appropriate: $query = "SELECT * FROM filesindex WHERE filename LIKE '".$searchterm."%' UNION SELECT * FROM filesindex WHERE creation LIKE '".$searchterm."%' UNION SELECT * FROM filesindex WHERE length LIKE '".$searchterm."%' UNION SELECT * FROM filesindex WHERE wall LIKE '".$searchterm."%' UNION SELECT * FROM filesindex WHERE location LIKE '".$searchterm."%'"; Or ideally, is there an easier way that involves less hardcoding to search a table. Any ideas? Thanks

    Read the article

  • MySQL: Insert row on table2 if row in table1 exists

    - by Andrew M
    I'm trying to set up a MySQL query that will insert a row into table2 if a row in table1 exist already, otherwise it will just insert the row into table1. I need to find a way to adapt the following query into inserting a row into table2 with the existing row's id. INSERT INTO table1 (host, path) VALUES ('youtube.com', '/watch') IF NOT EXISTS ( SELECT * FROM table1 WHERE host='youtube.com' AND path='/watch' LIMIT 1); Something kind of like this: INSERT ... IF NOT EXISTS(..) ELSE INSERT INTO table2 (table1_id) VALUES(row.id); Except I don't know the syntax for this.

    Read the article

  • MySQL Query like not returning correct results

    - by Herr Kaleun
    Hello friends, i've a MySQL query that should return some rows that have the letters Ö or Ü in it but it actually does not. The query code is this: $this->db->like('title', $text ); It's PHP CodeIgniter active query. Lets assume we have 2 rows. 1. Büm 2. Bom if i search for Bü, the 1. row has to be returned but it does not. When i search for Bo the second row gets returned successfully and when i search for B both rows are returned. How could i fix this? What may be the underlieng cause? Thanks for reading.

    Read the article

  • MySQL script to delete data in chunks until everything lower then id has been deleted

    - by Chriswede
    I need an MySQL Skript which does the following: delete chunks of the database until it has deleted all link_id's greater then 10000 exmaple: x = 10000 DELETE FROM pligg_links WHERE link_id > x and link_id < x+10000 x = x + 10000 ... So it would delete DELETE FROM pligg_links WHERE link_id > 10000 and link_id < 20000 then DELETE FROM pligg_links WHERE link_id > 20000 and link_id < 30000 until all id's less then 10000 have been removed I need this because the database is very very big (more then a gig) thank in advance

    Read the article

  • MySQL: filling empty fields with zeroes when using GROUP BY

    - by SaltLake
    I've got MySQL table CREATE TABLE cms_webstat ( ID int NOT NULL auto_increment PRIMARY KEY, TIMESTAMP_X timestamp DEFAULT CURRENT_TIMESTAMP, # ... some other fields ... ) which contains statistics about site visitors. For getting visits per hour I use SELECT hour(TIMESTAMP_X) as HOUR , count(*) AS HOUR_STAT FROM cms_webstat GROUP BY HOUR ORDER BY HOUR DESC which gives me | HOUR | HOUR_STAT | | 24 | 15 | | 23 | 12 | | 22 | 9 | | 20 | 3 | | 18 | 2 | | 15 | 1 | | 12 | 3 | | 9 | 1 | | 3 | 5 | | 2 | 7 | | 1 | 9 | | 0 | 12 | And I'd like to get following: | HOUR | HOUR_STAT | | 24 | 15 | | 23 | 12 | | 22 | 9 | | 21 | 0 | | 20 | 3 | | 19 | 0 | | 18 | 2 | | 17 | 0 | | 16 | 0 | | 15 | 1 | | 14 | 0 | | 13 | 0 | | 12 | 3 | | 11 | 0 | | 10 | 0 | | 9 | 1 | | 8 | 0 | | 7 | 0 | | 6 | 0 | | 5 | 0 | | 4 | 0 | | 3 | 5 | | 2 | 7 | | 1 | 9 | | 0 | 12 | How should I modify the query to get such result? Thanks.

    Read the article

  • MYSQL Inserting rows that reference main rows.

    - by Andrew M
    I'm transferring my access logs into a database. I've got two tables: urlRequests id : int(10) host : varchar(100) path: varchar(300) unique index (host, path) urlAccesses id : int(10) request : int(10) <-- reference to urlRequests row ip : int(4) query : varchar(300) time : timestamp I need to insert a row into urlAccesses for every page load, but first a row in urlRequests has to exist with the requested host and path so that urlAccesses's row can reference it. I know I can do it this way: A. check if a row exists in urlRequests B. insert a row in urlRequests if it needs it C. insert a row into urlAccesses with the urlRequests's row id referenced That's three queries for every page load if the urlRequests row doesn't exist. I'm very new to MySQL, so I'm guessing that there's a way to go about this that would be faster and use less queries.

    Read the article

  • MySQL Query still executing after a day..?

    - by Matt Jarvis
    Hi - I'm trying to isolate duplicates in a 500MB database and have tried two ways to do it. One creating a new table and grouping: CREATE TABLE test_table as SELECT * FROM items WHERE 1 GROUP BY title; But it's been running for an hour and in MySQL Admin it says the status is Locked. The other way I tried was to delete duplicates with this: DELETE bad_rows.* from items as bad_rows inner join ( select post_title, MIN(id) as min_id from items group by title having count(*) 1 ) as good_rows on good_rows.post_title = bad_rows.post_title; ..and this has been running for 24hours now, Admin telling me it's Sending data... Do you think either or these queries are actually still running? How can I find out if it's hung? (with Apple OS X 10.5.7)

    Read the article

  • MySQL temp table issue

    - by AmyD
    Hi folks! I'm trying to use temp tables to speed up my MySQL 4.1.22-standard database and what seems like a simple operation is causing me all kinds of issues. My code is below.... CREATE TEMPORARY TABLE nonDerivativeTransaction_temp (accession_number varchar(30), transactionDateValue date)) TYPE=HEAP; INSERT INTO nonDerivativeTransaction_temp VALUES( SELECT accession_number, transactionDateValue FROM nonDerivativeTransaction WHERE transactionDateValue = "2010-06-15"); SELECT * FROM nonDerivativeTransaction_temp; The original table (nonDerivativeTransaction) has two fields, accession_number (varchar(30)) and transactionDateValue (date). Apparently I am getting an issue with the first two statements but I can't seem to nail down what it is. Any help would be appreciated. Amy D.

    Read the article

  • Match two mysql cols on alpha chars (ignoring numbers in same field)

    - by Steve
    I was wondering if you know of a way I could filter a mysql query to only show the ‘alpha’ characters from a specific field So something like SELECT col1, col2, **alpha_chars_only(col3)** FROM table I am not looking to update only select. I have been looking at some regex but without much luck most of what turned up was searching for fields that only contain ‘alpha’ chars. In a much watered down context... I have col1 which contains abc and col two contains abc123 and I want to match them on alpha chars only. There can be any number of letters or numbers. Any help very much wel come

    Read the article

  • Mysql Query - Order By Not Working

    - by jwzk
    I'm running Mysql 5.0.77 and I'm pretty sure this query should work? SELECT * FROM purchases WHERE time_purchased BETWEEN '2010-04-15 00:00:00' AND '2010-04-18 23:59:59' ORDER BY time_purchased ASC, order_total DESC time_purchased is DATETIME, and an index. order_total is DECIMAL(10,2), and not an index. I want to order all purchases by the date (least to greatest), and then by the order total (greatest to least). So I would output similar to: 2010-04-15 $100 2010-04-15 $80 2010-04-15 $20 2010-04-16 $170 2010-04-16 $45 2010-04-16 $15 2010-04-17 $274 .. and so on. The output I am getting from that query has the dates in order correctly, but it doesn't appear to sort the order total column at all. Thoughts? Thanks.

    Read the article

  • PHP MySQL Syntax Error 'You have an error in your SQL syntax'

    - by Alec
    I cannot figure out the issue with my code here. I am trying to take info from the table, then subtract 1 second from Current_Time which looks like '2:00'. The problem is, I get: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Current_Time) VALUES('22')' at line 1" I don't even understand where it gets 22 from. Thanks, I really appreciate it. if (isset($_GET['id']) && isset($_GET['time'])) { mysql_select_db("aleckaza_pennyauction", $connection); $query = "SELECT Current_Time FROM Live_Auctions WHERE ID='1'"; $results = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($results)) { $newTime = $row['Current_Time'] - 1; $query = "INSERT INTO Live_Auctions(Current_Time) VALUES('".$newTime."')"; $results = mysql_query($query) or die(mysql_error()); } }

    Read the article

  • MySQL query problem

    - by SaltLake
    I've got MySQL table CREATE TABLE stat ( ID int NOT NULL auto_increment PRIMARY KEY, TIMESTAMP_X timestamp DEFAULT CURRENT_TIMESTAMP, # ... some other fields ... ) which contains statistics about site visitors. For getting visits per hour I use SELECT hour(TIMESTAMP_X) as HOUR , count(*) AS HOUR_STAT FROM cms_webstat GROUP BY HOUR ORDER BY HOUR DESC which gives me | HOUR | HOUR_STAT | | 24 | 15 | | 23 | 12 | | 22 | 9 | | 20 | 3 | | 18 | 2 | | 15 | 1 | | 12 | 3 | | 9 | 1 | | 3 | 5 | | 2 | 7 | | 1 | 9 | | 0 | 12 | And I'd like to get following: | HOUR | HOUR_STAT | | 24 | 15 | | 23 | 12 | | 22 | 9 | | 21 | 0 | | 20 | 3 | | 19 | 0 | | 18 | 2 | | 17 | 0 | | 16 | 0 | | 15 | 1 | | 14 | 0 | | 13 | 0 | | 12 | 3 | | 11 | 0 | | 10 | 0 | | 9 | 1 | | 8 | 0 | | 7 | 0 | | 6 | 0 | | 5 | 0 | | 4 | 0 | | 3 | 5 | | 2 | 7 | | 1 | 9 | | 0 | 12 | How should I modify the query to get such result? Thanks.

    Read the article

  • PHP MySQL Insert Data

    - by happyCoding25
    Hello, Im trying to insert data into a table in MySQL. I found/modified some code from w3Schools and still couldn't get it working. Heres what I have so far: <?php $rusername=$_POST['username']; $rname=$_POST['name']; $remail=$_POST['emailadr']; $rpassword=$_POST['pass']; $rconfirmpassword=$_POST['cpass']; if ($rpassword==$rconfirmpassword) { $con = mysql_connect("host","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydbname ", $con); } mysql_query("INSERT INTO members (id, username, password) VALUES ('4', $rusername, $rpassword)"); ?> Did I mistype something? To my understanding "members" is the name of the table. If anyone knows whats wrong I appreciate the help. Thanks

    Read the article

  • Optimize MySQL database query

    - by rajeeesh
    I had a commenting application in my web site. The comments will store in a MySQL table . table structure as follows id | Comment | user | created_date ------------------------------------------------------ 12 | comment he | 1245 | 2012-03-30 12:15:00 ------------------------------------------------------ I need to run a query for listing all the comments after a specific time. ie .. a query like this SELECT * FROM comments WHERE created_date > "2012-03-29 12:15:00" ORDER BY created_date DESC Its working fine.. My question is if I got a 1-2 lakh entry in this table is this query is sufficient for the purpose ? or this query will take time to execute ? In most cases I have to show last 2 days data + periodically ( interval of 10 mins ) checking for updates with ajax from this table ... Please help Thanks

    Read the article

  • Can't Connect To Local Mysql Using IP Address, but CAN connect from remote server

    - by user1782041
    Here's an interesting one that does not seem to fall into any of the mysql connection issues I've read about or searched for: On an Ubuntu 12.04 box I had some system updates waiting to install, and I took care of that this evening. After the install, I started seeing some errors in my syslog complaining about a particular php script that could no longer connect to the mysql instance on the box. Here is the specific error: PHP Warning: mysql_connect(): Can't connect to MySQL server on '192.168.0.40' (4) Now, the server's IP address is 192.168.0.40, and I've checked to make sure that I have mysql listening on 0.0.0.0 so that I can connect using either "localhost" or "192.168.0.40". Here's where things get odd: From the local machine, if I try the following: mysql -uroot -p -h192.168.0.40 I get this error: ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.40' (110) I've checked, and error 110 indicates an OS timeout, and error 2003 is the mysql generic "can't connect" error. This indicates that it is not permissions with the user. However, if I do the same thing from a remote machine (say, from 192.168.0.30), I log right in with no problems. Futher, other scripts on the local machine that connect to mysql using "localhost" for the host rather than "192.168.0.40" connect with no problems. Also, I can connect via the mysql socket with no problems both from the command line and php scripts. So, this feels like a networking issue of some kind on the local box, but there are no iptables rules on this box (it is firewalled externally) and I can't figure out what else may be causing this. This problematic script worked perfectly prior to the latest system update. For now, I'll simply change the script to connect via localhost, but I'd really like to know why it broke for 2 reasons: There may be other scripts that connect using 192.168.0.40 that don't run very often which are now broken. Auditing them all will take more time than I feel like devoting at the moment. I'm curious, and want to know why it broke so I can fix it correctly. Any help?

    Read the article

< Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >