mysql

mysql query for transposing data

I need to transform the values in my column into different columns. Example data with me currently: id dtime std_time ifInOctets ----------------------------------------------------- 4 1279027201 13:20:01 1.34E+08 1 1279027201 13:20:01 34562 2 1279027201 13:20:01 9.72E+07 4 1279027201 13...

One-to-many Query in MySQL

What's the best way to query one-to-many in MySQL? This is a simplified version of the database I am working on (if anything doesn't look right tell me): CREATE TABLE Tenant( tenant_id int NOT NULL, first_name varchar(20), last_name varchar(20), PRIMARY KEY (tenant_id) ); CREATE TABLE Rent( tenant_id in...

Nested mysql_query() - Resets first result's pointer?

I have a friend who's using FluxBB and he has just installed a modification for this forum software. The viewtopic.php file has a while-loop which does a mysql_fetch_assoc() on a result object. Inside of this loop there's a second mysql_fetch_assoc() on a second result object. The reason for the nested while loop is that there are many...

MySQL self-join for an EAV based stock control application

This question relates to the schema I suggested in my original question regarding a stock control application. I'm trying to create a MySQL query that provides the current stock for a particular item. The query is working but I wondered whether there is a more efficient way of obtaining the information I require. SELECT 's'.*, '...

Is this query possible?

Sorry in advance for the massive queries. I've been trying and cannot for the life of me get this query to work. It's adding wins and losses to both users when two logged in users are playing against each other. (It's rock paper scissors). I can make it work for a single user, but when I try to gather a 'stats-table' summing over use...

LEFT JOIN of a string

On part of my site, users enter multiple search terms. Each of these search terms may return 0 rows, or return several. I perform a UNION on all the searches and get the rows. Thing are much easier for me if I can get all the search terms in the response, regardless of whether they return any rows. Is there a way to essentially LEFT ...

What does it mean when open source projects (like MySQL) get sold

I've always released my personal code, all of which are small projects, under a GPL license. My reasons are more about personal preferences, but now I'm trying to understand the dynamics of open source and GPL beyond those personal preferences of mine. I'm looking at GPL projects like MySQL and I'm trying to understand what it means wh...

Determine MySQL state with Perl's DBI module

I'm using a Perl script to dump the contents of a MySQL db. The Perl module I'm using is CPAN's DBI. Is there any way to tell if the state of the db has changed since the last dump so that I don't need to re-dump the db? ...

Return distinct and null records from a mysql join query

Is there any way to return distinct values with blank/null data from a table join. Best to explain with my example below. Table "orders" order_id | order_total 1 | 10 2 | 20 3 | 50 Table "order_items" item_id | order_id | name | qty_ordered | base_price | row_total 1 | 1 | Product | 1 ...

Getting MySQL Schemas for All Tables

I want to download/backup the schema of an entire MySQL database. Is there a way to easily do this? I haven't had much luck using a wildcard, but that could be an error on my part. ...

Is there a way in MySQL to choose an order for the beginning and end of rows returned?

Look at this simple query SELECT id FROM users Now, say I wanted to have users with ids ordered 4, 5, 7, 8, then I don't care about the middle, and finally I want the last ones to be 55, 56, 58. So the returned rows would be something like this (\n a new row) 4 // explicitly chose these as the start rows 5 // " " 7 // " " 8 // "...

how to insert this text in mysql

i want to insert some text in mysql but text have double quote "" in middle of the text then insert query failed what i do in c# to solve this issue Incorrect string value: '\xE0\xA4\x85\xE0\xA4\xAD...' for column 'colname' at row 1 ex: this is a simple "text" ...

Best methodology for PHP+APACHE+MYSQL Development

Hi! I want to start learning PHP. I have had a look at the various options available to install the PHP+MySQL+Apache combination. But it all seems too cumbersome and a lot of editing to the CONF files always leads to one problem or the other. So I had a couple of questions to ask: 1) How will something like WAMP help me? If I instal...

How to store assignment of resources to one or more jobs in MySQL

I have different types of resources that can be assigned to a job. My resources, for now, are technicians and equipment. I would like to be able to store old assignments (aka, no static column in the resource tables referencing the job table). I've been considering using a table for each resource that tracks assignments, but I would lik...

Compare group of tags to find similarity/score with PHP/MySQL

My Question is, how do I compare a group of tags to another posts tags in my database to get related posts? To start off, I've searched the internet and stackoverflow to find out how to do this. My closest find was this post http://stackoverflow.com/questions/2153062/how-to-find-related-items-in-php. But it actually doesn't solve much f...

How do I setup a Doctrine relation for a foreign key that could point to different tables, depending on context?

I am creating an application, built with PHP, MySQL and Doctrine v1.2, that deals with ordered groupings of items, which can contain different types of items. For example, the group My Last Vacation can have images, video and textual notes. These items would be sortable so that they appear in the order that the end user specifies. Eac...

how to maintain paragraph?

i have a problem when i insert some articles which includes paragraph to database at the time of retrieval it display article but without paragraph. so it look like dirty writing on the page. so is there any trick or code for save article with paragraph & at time of display it shows as it is. ...

Efficient way to simulate full outer join in MySQL ?

According to Google search: since MySQL does not support full outer join, it could be simulated via union and/or union all. But both of these either remove genuine duplicates or show spurious duplicates. What would be correct and efficient way? This question seems relevant but couldn't get the answer of it. ...

How to select a record from a many to many table where one id exists in one but not another?

Sorry if that title didn't explain it well. Here is the table... I want to select product_id where it is in either 5 or 6 but not if it is in 7. Maybe I've lost the plot, but I came up with this query SELECT `product_id` , `category_id` FROM `wp_wpsc_item_category_assoc` WHERE ( `category_id` =5 OR `category_id` =6 ) AND `category_...

(many rows + two tables) or (one table + comma separated values in one field)

Hi, I know that to have a mysql column whose content is a string of values separated by commas is not the standard. However, if I will never need to search by such values (they are processed by third program) and separating them would result in many new rows and a new table: would it be justified to keep it as a comma-separated string ...