mysql-query

Retrieving data from MySQL in one SQL statement

Hi all, If I'm getting my data from Mysql like so: $result = $dbConnector->Query("SELECT * FROM branches, businesses WHERE branches.BusinessId = businesses.Id ORDER BY businesses.Name"); $resultNum = $dbConnector->GetNumRows($result); if($resultNum > 0) { for($i=0; $i < $resultNum; $i++) { $r...

Slightly complex mySQL Query

Hello, I have a table which has the following id timestamp ------------------------------------- 1 1247046037 4 1247047437 5 1247047438 6 1247048738 Now I want to return all those ids which are 3 minutes apart from the previous id. In the above example it should return 1,4,6. How should I go about doing this?...

Merging two tables with a common unique field in MySql

The problem if have is this. We have taken over a website which has an active member community. We've been given the application and database dump and have the site running on a new server successfully and the DNS has been switched. The problem is that the database has come out of sync in the time it took to get the files to us and t...

Getting my signout button to work

Hey there, I am trying to get my signout button to work. This is what I have in my code: <!-- Signed In --> <?php if($_SESSION['*****']['AUTH']) { ?> <div id="signOut"> Sign Out </div> <div id="signIn"> <form name="sendEmail" action="index.php" method="post"> <input type="text" name="name" class="text"/> <i...

How to write SQL query for these 5 tables?

I am writing an application that helps book exchange between users. I am using PHP and MySQL, and I am pretty new to them both. I have 5 tables, 3 data tables and 2 service tables: user: with user attributes (user_id, name, birth... etc). book: with book attributes (book_id, name, author, publisher... etc). copy: represents actual co...

Using temporary, using filesort a bad idea in mysql?

Hi all. I am trying to optimize my mysql queries to avoid 'using temporary, using filesort'. I could use some help. First; here is the explain Here is the Query select pf.*,m.login,m.avatar from profile_friends pf, members m where pf.friend_id = m.id and pf.member_id = 16586 order by m.lastLogin desc limit 0,24; mysql> EXPLAIN s...

How can I select records in MySQL when a foreign key doesn't return anything?

SELECT videos.id, videos.game_id, videos.xbox360, videos.ps3, videos.pc, videos.wii, videos.other, videos.thumbnail, videos.vid_info, videos.sdvid, videos.hdvid, UNIX_TIMESTAMP( videos.date_added ) , game_data.name, AVG( video_ratings.rating ) FROM videos, game_data, video_ratings WHERE videos.game_id = game_data.id AND videos.i...

MySQL - Finding out Balancing Figure From 2 Tables

I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table product_id bigint(20) qty float Sample Data Stock Table product_id---qty 1---10 2---11 3---20 4---50 1---10 3---10 Sales Table product_id---qty 1---2 2---5 3---20 4---40 1---7 I want the following Output after running the Query product_id---qty ...

format integer to string

I have an integer field in a table and I want to make a query to format the integer value of this field in an char or double field with a especific format. For example, if my value in the table is 123456 I want to format it as "###.###" what means the result should be like this: 123.456 I've done this using CONCAT function, but the res...

windows cmd connection to remote mysql dbf

is there a way of how to connect to mysql dbf on a remote server and run sql queries using windows command line? ...

SQL: return percentage without decimal place

Quick question; is there a way to apply numeric type on select statement? exmaple usage select (t1.f_count / (select count(*) from utb where user_id = 1))*100 as ratio i need this to returns 60 instead of 60.0000 ...

MySQL Math and COUNT(*) in LIMIT

Is it possible to let MySQL LIMIT have an offset of the total number of rows divided in 2, so that the query would look something like this: SELECT * FROM test LIMIT COUNT(*) / 2, 5 Where 5 is just a number. ...

MySQL multiple tables and multiple rows

Lets say I have a table in MySQL called articles, that has a column called article_id. I also have another table called links which have two columns called article_id and link. Every article can have multiple links attached, let's say that article_id=2 have two links: articles: article_id | text -----------+------ 2 | blah li...

sql complex group query

I have a table with the following rows: id. type - link 1. image - http://1 2. image - http://2 3. text - none 4. video - http://.. 5. image - http://.. 6. text - http://.. I want to group the type (image) by date, so they show as single row. In this example, the first two images will merge together and output will be like...

4 table join so that only 1 response is given for each company instead of a result for each campaign

Thanks for your help! I'd like to output all companyName entries that have uploads across any of their serverFiles as: companies.companyName - count(files.fileID) - sum(serverFiles.uniqueUploads) Initech Ltd. - 11 - 24931 Epiphyte Inc. - 23 - 938821 Here are the relavent parts of my table structure: Table: companies c...

PHP MYSQL multiple or single DISTINCT/UNIQUEvalues

Currently I have this query: SELECT column1,column2 FROM table column1 needs to be distinct, column2 does not. SELECT DISTINCT column1, NON-DISTINCT column2 FROM table Now I know that doesn't make sense but I need column1 to be distinct and column2 to be anything. How would I do that. ...

preg_replace easy for a pro

i want to find first select ... from and replace that only, following code replace all select..from in sql query, i just need for first select..from preg_replace('#select(.*?)from#is', "select count($expr) as counted from", $sql); ...

SQL: COUNT() with items appearing multiple times in one-to-many relationship? Alternative to GROUP BY?

I have a query listing product categories, by supercategory > category. The query counts the number of products in each category (COUNT(ptc.catid)). Howewer: the query doesn't let a category appear twice (a category can be linked to multiple supercategories). How can this be re-written so categories (c.title) can be listed under multip...

How to do a joined query in the ZF tables interface?

Hi there, I have the db and my tables look like this: What I want to do is to get all models where manufacturers name column starts with A. Which means that that simple part of query should be like $manufacturers->fetchAll("name LIKE '$letter%'"); I am trying to accomplish this with ZF relations but it ain't going, so any kind of he...

help me resolve this query to insert entries in tables

I am working backwards with a query. I have a select query that fetches some rows...but now I am working backwards and want to insert entries in concerned tables to that the select query brings back the stuff I inserted. Select Query: SELECT DISTINCT a.catalogID, a.topicID, a.topicShortName FROM catalog_lu_topics a LEFT JOIN catalog ...