mysql-query

SQL query to find out some of three fields from three different table

I have three tables, tableA (id, A), tableB (id,B) and tableC (id,C). id is unique and primary key. Now I want to run a query on these three tables to find out sum of values of A,B and C for every id. (i.e. if id 1 is present in tableA but not in tableB then value B should be considered as 0 for id 1).example: tableA: id A 1 5 2 6 ...

Need Mysql Query ( Thread Changed)

Hi all, I have changed my thread as my last thread also same like that. But actually this is my requirement. I have n number of users with different articleId. If I pass the articleId, I want to get the results like how many different users viewed that article. table1: recId userId articleId ----- ------ -------- 1 ...

mysql insert if row does not exist already in a table with NO UNIQUE FIELDS

Looking for a while now already for how to accomplish this. Seems that all solutions need unique fields with indexes. ...

MySQL query with equality and please all results...

Hello, I am quite new to MySQL and it is great in reducing data through queries. However, it seems to be hard to get both records, if you want records containing duplicates. The table looks like: ID Value more columns.. 1 4 1 4 1 5 2 4 3 5 3 5 4 4 4 5 I want both(!) records with duplicate values, li...

Best update query for mysql table

Hello, I have a file hosting site where I provide a point for every unique download to user. Sample of my table These points can be redeemed by user. So for example if a user redeems 100 points than what is the best query to reduce points available from each row till 100 points are reduced. Thank You. ...

MySQL stored procedure causing problems?

EDIT: I've narrowed my mysql wait timeout down to this line: IF @resultsFound > 0 THEN INSERT INTO product_search_query (QueryText, CategoryId) VALUES (keywords, topLevelCategoryId); END IF; Any idea why this would cause a problem? I can't work it out! Hi guys, I've written a stored proc to search for products in cer...

How update order of rows stored in a mysql table?

I want to update the order so that GALLERY goes before PRODUCTS. What should be the query to do this? Sorry for my English. ...

MYSQL query to return most recent entry regardless of date entered

Hello, I am really bad explaining but I'll try... I want to create a MYSQL query that returns the data based on the last entry in the table. I did it fine with the MAX function based on the date, but I need more advanced in terms of finding the last item entered by a specific product and return the last qty even if it's not the same dat...

SQL Question ... should I use a Group By???

I have a situation where I need to group data by a portfolio name, then sort through the data and display check boxes. Here's the table structure. Table A -------- portfolio_id portfolio_name Table B ------- file_id portfolio_id (Foreign Key fk_port_id references portfolio_id in table A) file_name Basically Table A links to table B ...

How can I put two queries in one mysql_query?

I'm trying to do something like this: mysql_query(" UPDATE name SET money = money + 1; UPDATE surname SET money = money + 1; "); but it doesn't work. It's just example, but my question is: How can I put two or even more queries in one mysql_query? ...

PHP echo repeating rows only once

Hi all, I have 2 tables. One table is 'headings' & contains Headings and the other one is 'sub-headings' and contains Sub-headings that are (& must be) classified under the Headings and must have a respective Heading. A Sub-Heading can have only one Heading and many sub-headings can have the same Heading. So consider the following forma...

MYSQL Query Help

I need to get a SQL Query that I can execute to extract certain data. Here are the details: DB Type: MySQL DB Name: adminDB Table Name: licenseinfo Field Name: LicenseNumber So the data in the LicenseNumber Column looks like this: ( this is just a sample there are 300,000 Records) SSCY-334-0W2-5AA SSCY-238-2W1-5F9 SSCY-378-0W5-...

Change a field across many MySQL tables

Scenario: I have users that want to be able to change their username (unfortunately I didn't think about adding this functionality when I started the site), but the MySQL database has 110 tables. Am I going to have to just make a script that executes 110 queries to update the username in each table (and remember to update the script whe...

MySQL Query - Comparing rows with outside data

Ok, I have an array outside of the SQL database in the following format: $currStats['USERNAME'][SKILL NUMBER][1-3] Username obviously pertains to a specific user, skill number is the number of the skill and 1-3 is either XP, rank or level. So $currStats['Jimmy93'][0][1] would return the Overall (Skill #0) level of Jimmy93. Now, that ...

mysql query adding to a decimal doubles value of the addend for some reason

I am trying to add a value ($credit) to the value of a decimal (9,2 max length) field in a mysql database. The problem is that when I do this, it doubles the $credit and then adds it for some reason. I just want it to add it. The code I am using is: mysql_query("update $table set earnings = earnings +$credit where username = ('$member')...

(PHP & mySQL) Treat rows as columns

Hi all, I am working on PHP & mySQL based website. I am trying to setup the 'Settings' page in administration panel where I can enter different settings to manage the site. The settings can range upto 100 (or even more) depending upon the requirements. So instead of making 100 columns (and increase if I have to add more columns in future...

[SOLVED]Mysql optimization

Here you have a screenshot from my table structure:http://img64.imageshack.us/img64/54/pictx.jpg On my site I have two fields for the search, one for the city(ort) and one for industry(branche), and if I search for: Frankfurt verschierung, let's say that in the field for city I have: Frankfurt and in the field for industry(branche) I ha...

PHP wordpress style related posts

Do you know how wordpress decides which related posts to show?I mean I know if it has tags, then it's easy but if it doesn't? Best Regards, ...

Order a mysql query alphabetically

Let's say that I have the following code: SELECT * FROM table where company LIKE '%Auto%' And I receive more results, and I want to have an option to sort the results alphabetically, let's say that the user wants to sort the search results for the ones which start with "C"! Best Regards, ...

Repairing table in mysql

hi guys, i tried to repair a table in mysql .... but it returned an error like .. The storage engine for the table doesn't support repair plz try to help.. ...