mysql

sql doesn't wants to leave empty fields in a table empty when i call echo in PHP

Whenever i call a SQL function it fills out everything but empty fields accordingly to id number where id number says which record of name, account it takes. SQL instead fills the empty fields with data from previous id record. How to tell SQL to not fill the empty fields and leave them empty as they are ? ...

how to convert json to string

how do i convert a json object to a string i want to insert a json object to a mysql DB ...

How do i truncate a post (HTML/Markdown) but not give invalid markup

is there a way i can truncate a post. eg. create a blog summary. while not breaking the markup? 1st i am thinking of HTML if that can be done, how do i work on markdown posts i use PHP/Zend Framework/MySQL/Doctrine2 ...

Database table normalization question

I'm making an online calendar. One will be able to create en event and then have the possibility to choose to add "infinite" or "from" to "end" datetime. And if you choose to add a "from" to "end" you can choose it to be no repeat or repeat every day, every week or every month. I wonder what is the best way to create these relations. ...

Calculating total time duration in MySQL

i have a table data like this (int) (time) [mySQL datatype] Id Duration ------------------ 1 00:10:00 2 10:10:00 3 03:00:00 4 04:13:00 i want to calculate the total duration from this table, how can we do it. like 17:33:00. Could anybody please provide mysql query to calculate this. ...

SQL: how do i order by a field if its not null else use another field

i want to sort my Posts by dtModified (datetime modified) if its not null (post modified b4), else sort by dtPosted (datetime posted) ...

Unicode characters become question marks after inserting into database

When I insert some text written in unicode into database, they become question marks. Database encoding is set to utf-8. What else may be incorrect? When I check in phpmyadmin there are question marks inserted only! This is the code I use for connecting to database: define ("DB_HOST", "localhost"); // set database host define ("DB_USER...

SQL: Any straightforward way to order results FIRST, THEN group by another column?

I see that in SQL, the GROUP BY has to precede ORDER BY expression. Does this imply that ordering is done after grouping discards identical rows/columns? Because I seem to need to order rows by a timestamp column A first, THEN discarding rows with identical value in column A. Not sure how to accomplish this... I am using MySQL 5.1.41 ...

MySQL question.

How can i exclude a user with a user_id of 1 for example from the following query below? Here is My MySQL code. "SELECT users.*, COUNT(*) as coun, users_comments.user_id FROM users_comments INNER JOIN users ON users_comments.user_id = users.user_id GROUP BY users_comments.user_id ORDER BY coun DESC LIMIT 5" ...

remote server connect with mysql

Hi, I have mysql 5.1 set up and running. I need to connect to: location: comm.eng.bxg.com name: amntxy user: username pswd: password I have tried using mysql -h amntxy -u username -p Also tried: use amntxy and use comm.eng.bxg.com/amntxy But I am unable to connect. I get the following error: ERROR 2005 (HY000): Unknown MySQL ...

LIMIT ignored in query with GROUP_CONCAT

Hello, I need to select some rows from second table and concatenate them in comma-separated string. Query works well except one problem - It always selects all rows and ignores LIMIT. This is part of my query which gets that string and ignores LIMIT: select group_concat(value order by `order` asc SEPARATOR ', ') from slud_data ...

Query select a bulk of IDs from a table - SQL

I have a table which holds ~1M rows. My application has a list of ~100K IDs which belong to that table (the list being generated by the application layer). Is there a common-method of how to query all of these IDs? ~100K Select queries? A temporary table which I insert the ~100K IDs to, and Select query via join the required table? Tha...

"Unknown column" because of subquery-in-subquery.

I need to do subquery in subquery what causes "Unknown column 't1.product_id' in 'where clause'". It's on line 7. in my example. How to solve this problem? SELECT *,product_id id, (SELECT GROUP_CONCAT (value ORDER By `order` ASC SEPARATOR ', ') FROM ( SELECT `order`,value FROM slud_data LEFT JOIN slud_...

Install script - How to check if database tables already exist?

Hi! I found out how to find if the database exists with this code: if(mysql_select_db('db-name')) return true; But i would like to check the tables inside the database. Here is the code: error_reporting(0); session_start(); global $_ERROR; $_ERROR = array(); $installed = false; if($_POST) { $num = 0; foreach($_POST as $ke...

Putting database logic in the application instead of trigger, stored procedures, constraints etc.

I'm using Rails and it does not provide support for database specific actions like triggers, stored procedures and various constraints (not all of them). I wonder if I should put the database logic in the application itself instead. Because then you can make more complex logic than the database provides and it is also database independ...

Mutex contention in MySQL

I heard about MySQL has scalability issue in SMP platform, due to the mutex contention. But can anyone give me a sample scenario? Reference: http://mysqlha.blogspot.com/2008/08/mutex-contention-in-mysql.html ...

SELECT JOIN in same table ON multiple rows...

I have a table with an itemID and a categoryID columns. Both columns are primary keys because each item can have more than 1 category: itemID | catID ----------------- 1 | 2 1 | 3 1 | 4 2 | 2 2 | 3 2 | 4 I want to select items with the same categories (based on all the item categories,...

Pictures & Tags - Database Design Question

I have 3 tables which allows me to get all tags of some picture, or all pictures with a specific tag. I would like also to know the number of times each tag exist. How could I get this info using MySQL ? Is it worth to add a "Count" column to the Tags table to hold this info ? Files Table File ID File Name ... ------- ------...

MYSQL delete where value = multiple POST values

I'm trying to put this, check_box=147&check_box=148&check_box=146 etc.. into $delete_selected = $connection->real_escape_string($_POST['check_box']) $sql = "DELETE FROM categories WHERE cat_id = '$delete_selected'"; but it only deletes the first check_box value. Is there a way to loop through all the values? ...

[SQL] Related rows based on text columns

Given that I have a table with a column of TEXT in it (MySQL or SQlite) is it possible to use the value of that column in a way that I could find similar rows with somewhat related text values? For example, I if I wanted to find related rows to row_3 - both 1 & 2 would match: row_1 = this is about sports row_2 = this is about study row...