mysql

MySQL: Select distict field, but get the rest of the columns as well?

I want to select distinct product_series, but I want all the other columns too. This is my query as it stands: SELECT DISTINCT product_series FROM cart_product WHERE product_brand = "everlon" AND product_type = "ring" AND product_available = "yes" But this only gives me product_series, but I need all the other columns in that row...

Live AJAX content

My friend and I maintain a submission site with comments. We want to know if it is possible to have a constant AJAX connection. Basically, each submission has a comments section. My friend had an idea of having an alert appear on the page everytime a new comment came in. So, would it be possible to keep up a constant link between the AJA...

Mysql - How do I order results by alternating (1,2,3, 1, 2, 3, 1, 2, 3,) rows, is it possible?

I want to order my results by client 1, 2, 3, then again client 1, 2, 3, and so on. Is there a way to do this without using a for loop or making three separate queries? Not only that, but I am working with paginated data so it needs to return x results, but consistently. Any ideas? GROUP BY maybe? client_id project_id project_name ...

Foreign Key reference in mysql innodb

Simply put: I have a table with 2 columns: one is username and other is nickname. I have another table where I have 2 columns: one is username and other is countNicknames. I want countNicknames to contain the number of nicknames each user has (and whenever I insert a new nickname to the table1, the value under table2.countNicknames will...

How to use Objective C to send device token for push notifications and other user settings to sql table on server

Ideally, I would like to send an HTTP Request using POST to the Push Notification Server that contains the device token as well as some user-defined settings. From there I can set up a php script on the server to deal with the incoming data and input it into an sql table. If this is the only way to do it, how would I go about initiating ...

Voting eachtime sets to 1 How to solve this?

Each time i vote up or down it just sets an 1. But i want that votes_up=votes_up+1 inkrements eachtime i vote up. this is php code public function voteUp($id) { $this->initDB(); $q="update twitter.tweets set vote_up=vote_up+1 where id=$id"; $this->db->query($q); } the result is Down Votes:1 Up Votes:1 Total Vot...

Why won't this simple SQL statement work?

dateposted is a MySQL TIMESTAMP column: SELECT * FROM posts WHERE dateposted > NOW() - 604800 ...*SHOULD*, if I am not mistaken, return rows where dateposted was in the last week. But it returns only posts less than roughly one day old. I was under the impression that TIMESTAMP used seconds? IE: 7 * 3600 * 24 = 604800 ...

Data visualization tool for database-query results

Hi, i looking for a tool, that can visualize the result of database query (MySQL, SQLite3 etc.) For example, i would like to have results of following query (it is SQLite3 syntax) ... SELECT count(*) FROM visits v GROUP BY date(v.visit_time) ... to be plotted graphically. (number of visits for each day) Is there any tool for it ? ...

Best to use * when calling a lot of fields in mysql?

I know generally it is always better performance to build mysql queries to name every item you need but for example on a profile page I might need every item except a few. SELECT user_name,f_name,l_name,country,usa_state,other_state,zip_code,city,gender,birth_date,date_created,date_last_visit, user_role,photo_url,user_status,frie...

Start a "throwaway" MySQL session for testing code?

Hi, If I want to be able to test my application against a empty MySQL database each time my application's testsuite is run, how can I start up a server as a non-root user which refers to a empty (not saved anywhere, or in saved to /tmp) MySQL database? My application is in Python, and I'm using unittest on Ubuntu 9.10. ...

MySQL Query Optimization

I'm performing a query that is looking for values in one table that are not in another. For example: SELECT id FROM table1 WHERE id NOT IN (SELECT id FROM table2); Both tables have about 1 million rows but only a few hundred that do not match values which are returned in the result set. The query takes about 35 seconds. Doing a sho...

Entity Framework - MySQL - Null Comparison!

Whats wrong with following code? :( int? parentFolderId = null; if( this.Request.QueryString ["folderId"] != null ) parentFolderId = Convert.ToInt32( this.Request.QueryString ["folderId"] ); f = ( from x in this.EntityDataContext.folders where x.parent_id == parentFolderId select x ).ToList(); It returns nothing! Though there ARE...

How to convert excel file into mdf file

i have an exel file. i want to change this file into mdf formmat. Plz tell me the full procedure, how i can convert this file. i m using excel 2003 nd sql server 2000. ...

MySQL Backup: Can I copying individual MyISAM table files to another server with different MySQL version and different OS?

I means copying individual MyISAM table files is: (shut down mysqld and copy the .frm, .myd, and .myi files from one database folder to another) Question: (a) can I use this way to backup MySQL database folder from one server to another server with different MySQL version? (b) can this backup files moved to different OS? (example: debian...

MySQL counting occurrence of values in a field

I've got a MySQL table containing 115 fields like these: v1q1 v1q2 v2q1 v2q2 v3q1 v3q3 (...) The records all contain one of the value 0, 1, 2, 3 or 4. Now I need to count for every field the number of records containing a 0, the number of records containing a 1, the number of records containing a 2,... (until 4). How I can acco...

apostrophes are breaking my mysql query in PHP

My database has name records that occasionally contain apostrophes, such as Joe's Bar and I've just coded a query script in PHP that grabs that field and sticks it into a select statement with the usual $query = "SELECT address FROM restaurants WHERE name='$name'"; and the apostrophe in some of the restaurant names derails the Love Train...

Database slow retriving/updating/inserting problem with more than 5mil records in each table

How to structure database to avoid slowdowns? (Engine: MyISAM) Currently i have database with more than 5milion records in one table that causes slow data retrieving. I'm currently searching for ways to structure database to avoid this kinds of database. (Database Engine MyISAM) Tables that cause problems are posts and comments having ...

What's better? Having 100 Tables with each 1,000 rows, or 10 Tables with each 10,000 rows?

With 10 Tables, I would have no joins. With 100 Tables, I would have one join per query. Which would show better performance? ...

specify what columns not to insert values into mysql table

I have a stored procedure that inserts a row into a table with an autoincremented column. It gives me a warning but succeeds if i simply put "" for the value of the autoincremented column. The way I get rid of the error currently is to specify which columns the insert values are for... "insert into app_table(app_id,name,...) values(...)"...

Is this the correct way to do this PHP class?

Hello I am just learning more about using classes in PHP. I know the code below is crap but I need help. Can someone just let me know if I am going in the right direction. My goal is to have this class included into a user profile page, when a new profile object is created, I would like for it to retrieve all the profile data from...