mysql-query

Data Partition in C#

I want to distribute a large amount of data to different C# applications. For example, my table contains millions of records. I would like to specify that first 3 millions records are processed by App1 and next 3 million in another C# application App2 and so on. Table rows are deleted and added as per requirement. Now I want to write a S...

Mysql rank function

Hi, I am not an expert in mysql.I need to find out rank of customers.Here I am adding the corresponding sql query for my requirement.Please help me to convert it to mysql. SELECT RANK() OVER (PARTITION BY Gender ORDER BY Age) AS [Partition by Gender], FirstName, Age, Gender FROM Person .Is there any function to find out ra...

Search for products with multiple criteria

I'm having a problem with fetching some data. The tables I have (for testing purposes): Products: product_id | product_name ----------------------------- 1 | product 1 2 | product 2 3 | product 3 Attributes: product_id | attribute_id | attribute_value -----------------------...

how to update a field which contains data using mysql

Hi all, I need to update a field which contains data. For ex: id fieldName 1 1,2 Now, I am getting 3,4 as another result which should be updated in id 1. That is now my result should be, id fieldName 1 1,2,3,4 How can this be done using mysql. Thanks in advance. ...

How to fill a column based on first column

I am making a mySQL table which lists ~70 products and information on whether they are compatible or not. For the sake of simplifying the question, I will pretend there were only four products. Product1 Product2 Compatible? A A Yes A B No A C Maybe A D ...

MySQL Subquery Causing Server to Hang

I'm trying to execute the following query SELECT * FROM person WHERE id IN ( SELECT user_id FROM participation WHERE activity_id = '1' AND application_id = '1' ) The outer query returns about 4000 responses whilst the inner returns 29. When executed on my web server nothing ha...

I'm having problem with SUM() in MySQL

Hi All, I want to fetch the BalanceAmt of a particular Customer attended by a particular attender. The criteria is that a customer may buy more than one items. Each bought items has been recorded individually. At some cases 'attender' value would be NULL. Here's my query: SELECT Customer, AttendedBy, SUM(BalanceAmt) FROM billing GROU...

Mysql client ran out of memory

Hi, When i try to combine 3 tables having 50K records and write a MySQL select query: I get "mysql client ran out of memory" Any help on how to overcome this will be highly appreciated. Thanks ...

PHP mySql update works fine on localhost but not when live

I have a a php page which updates a mySql database it works fine on my mac (localhost using mamp) I made a check if its the connection but it appears to be that there is a connection <?php require_once('connection.php'); ?> <?php $id = $_GET['id']; $collumn = $_GET['collumn']; $val = $_GET['val']; // checking if there is a ...

PHP MySQL select random rows

Hi, I have a problem selecting 6 random friends This is the query I've got so far: $result = num_rows("SELECT * FROM friends WHERE member_id = '".$_SESSION['userid']."'"); if($result >= 6) { $f_num = 6; } else { $f_num = $result; } for($i = 1; $i <= $f_num; $i++) { $q_get_member_friends = mysql_query("SELECT * FROM frie...

Filtering out MySQL query in PHP

Hey there, I'm doing some queries to a MySQL database that involves some user-input.. And I was wondering how to prevent injection attacks, like, for example, if someone were to type "; a-MySQL query here;" It would be executed, this would allow people access to compromise my system. I'm wondering how i could protect against things l...

A simple MySQL query taking forever (more than 20 minutes!)

Hello, Maybe you can help me. I need to query 3 tables in order to get data for a financial stock. The idea is to go to the instruments table, find the index for each instrument and then bring all the prices for that particular instrument together with the indicators that are on a separate table. Tables stockdata and indicators are bot...

MySQL filter query with relation

Hi, I'm having the following problem with 2 MySQL tables that have a relation: I can easily query table 1 (address) when I want a full list or filter the result by name or email or such. But now I need to query table 1 and filter it based on the relational content of table 2 (interests). So, I need to find a row (usually many rows) in ta...

How to create an MySQL query alias?

For example I use this select * from tab1; every 5 minutes. Is there a way to set up an alias p so that I can just do p instead and that query is executed? ...

MySQL Select, column with same name from multiple tables, order by another column with same name

I'm trying to select rows with a certain column name and order them by another column name. Here's my problem, into N simplified tables: table 1: id, username, datetime, comment table 2: id, username, datetime, vote . . . table N: id, username, datetime, bought I want to be able to select all rows where username='Some Name', ord...

Incorrect mySQL syntax error

I have inherited a site that includes a bespoke CMS. I moved hosts and after the move, I now get this error when trying to update pages; Query failed: 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 's Park Baptist Church So, the application is failin...

MySQL query, problem with my join?

I'am not sure that while problem, but take a look: I have 3 tables: Categories: id, icon, name; Subcategories: id, name, description, category_id; Topics: id, title, text, author, created, subcategory_id; Now I'm trying get this info(query): $String = "SELECT categories.id AS catid, categories.icon AS caticon, categories.na...

MySQL: How do I SUM non duplicates values when doing multiples JOINS

I try to SUM values from columns, from a query which contains some JOINS. Example: SELECT p.id AS product_id, SUM(out_details.out_details_quantity) AS stock_bought_last_month, SUM(order_details.order_quantity) AS stock_already_commanded FROM product AS p INNER JOIN out_details ON out_details.product_id=p.id INNER JOIN or...

Delete statement in a same table

Hi, I need to query a delete statement for the same table based on column conditions from the same table for a correlated subquery. I can't directly run a delete statement and check a condition for the same table in mysql for a correlated subquery. I want to know whether using temp table will affect mysql's memory/performance? Any h...

Mysql auto increment alternatives

Hi, I have the below table. create table mytable( physical_id int auto_increment, logical_id int, data varchar(20), version_start_date datetime, version_end_date datetime, primary key(physical_id), unique key(logical_id,version_start_date, version_end_date) ); The idea behind the schema is, I want to keep track of modification to ev...