mysql-query

Is it possible to call a procedure within an SQL statement?

Hi everyone I thought I would use a stored routine to clean up some of my more complex SQL statements. From what I've read, it seems impossible to use a stored procedure within an sql statement, and a stored function only returns a single value when what I need is a result set. I am using mySQL v5.0 SELECT p.`id`, gi.`id` FROM `sport...

ignoring saturday and sunday

I am pulling in all the records from my customer database(mysql) for the last ten days $offset1 =strtotime("-10 day"); $date3=date("Y-m-d",$offset1); SELECT * FROM customers WHERE date between '$date3' and '$date' AND customer.custid = '$custid' ORDER by date DESC I would like to leave out the dates falling on a saturday o...

MySQL Need help constructing query: join multiple tables into single row

Hello stackoverflowers, Forgive me if this question has been asked and answered, I've searched and found a few that look similar but I'm too much of a novice with SQL to adapt them to my needs. Also forgive me if I don't use the correct terminology, I know it can be annoying when someone asks a question and they don't even know enough t...

PHP While Loops from Arrays

I have a table that contains members names and a field with multiple ID numbers. I want to create a query that returns results where any values in the ID fields overlap with any values in the array. For example: lastname: Smith firstname: John id: 101, 103 I have Array #1 with the values 101, 102, 103 I want...

MySQL - get all unique values of a column, check if has a specific value

First off - apologies for the poor title, I have no idea how to describe it in a one-liner. I have a table - snippet is below. mysql> select * from playlistfiles; +-----------------------+--------------+-----------+ | FileName | PlaylistName | FileIndex | +-----------------------+--------------+-----------+ | File1 ...

sql query for fetching distinct records from table having count greater than 3

i have a table with coloumn id , name and city I want to fetch those rows where city is same and the number of rows are greater than 3. Is it possible in single sql query? ...

MYSQL - Help with a more complicated Query

I have two tables: tbl_lists and tbl_houses Inside tbl_lists I have a field called HousesList - it contains the ID's for several houses in the following format: 1# 2# 4# 51# 3# I need to be able to select the mysql fields from tbl_houses WHERE ID = any of those ID's in the list. More specifically, I need to SELECT SUM(tbl_houses.Hous...

Query to find tables modified in the last hour

I want to find out which tables have been modified in the last hour in a MySQL database. How can I do this? I am new to MySQL so please try to explain it as simply as you can. thank you! ...

mysql query to get unique value from one column

i have a table named locations of which i want to select and get values in such a way that it should select only distinct values from a column but select all other values . table name: locations column names 1: country values : America, India, India, India column names 2: state/Province : Newyork, Punjab, Karnataka, kerala when i selec...

Find a date between start_date and end_date

I have a table of events with a recorded start and end time. I want to find all events that occur on a specific date. Some events started a year ago and some will continue farther ahead. I would like to be able to pick for example May 20, 2010 and find all events occurring on that date. ...

MySQL: Is it faster to use inserts and updates instead of insert on duplicate key update?

I have a cron job that updates a large number of rows in a database. Some of the rows are new and therefore inserted and some are updates of existing ones and therefore update. I use insert on duplicate key update for the whole data and get it done in one call. But- I actually know which rows are new and which are updated so I can also...

iPhone SDK mySQL

Hello everybody, I'm starting on a new iPhone project, and this application mostly relies on mySQL. I have a mysql database running on my computer, and I need this application to send queries to the server to gain information. One example is creating and logging into an account. I have successfully done this on my windows vb.net applica...

A better way to build this MySQL statement with subselects

I have five tables in my database. Members, items, comments, votes and countries. I want to get 10 items. I want to get the count of comments and votes for each item. I also want the member that submitted each item, and the country they are from. After posting here and elsewhere, I started using subselects to get the counts, but this q...

How to Create MySQL Query to Find Related Posts from Multiple Tables?

This is a complicated situation (for me) that I'm hopeful someone on here can help me with. I've done plenty of searching for a solution and have not been able to locate one. This is essentially my situation... (I've trimmed it down because if someone can help me to create this query I can take it from there.) TABLE articles (article...

MYSQL - Selecting a specific date range to get "current" popular screensavers.

Let's say I have a screensaver website. I want to display the CURRENT top 100 screensavers on the front page of the website. What I mean is, "RECENT" top 100 screensavers. What would be an example query to do this? My current one is: SELECT * FROM tbl_screensavers WHERE WEEK(tbl_screensavers.DateAdded) = WEEK('".date("Y-m-d H:i:s",str...

Indexing only one MySQL column value

I have a MySQL InnoDB table with a status column. The status can be 'done' or 'processing'. As the table grows, at most .1% of the status values will be 'processing,' whereas the other 99.9% of the values will be 'done.' This seems like a great candidate for an index due to the high selectivity for 'processing' (though not for 'done'). I...

Sql query executing perfectly in phpmyadmin but giving warning while running on page

i don't know whats wrong with this sql query. SELECT * FROM main WHERE key LIKE '%$word%' its giving results in phpMyAdmin but giving warning while executing it in a php page. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ...

How to Display result of subquery rows as one column in MySQL?

Hi I have three tables Category, Movies and RelCatMov Category-table categoryid, categoryName 1 thriller 2 supsense 3 romantic 4 action 5 sci-fi Movies-table movieid, movieName 1 Avataar 2 Titanic 3 NinjaAssassin RelCatMov-table categoryi...

what is the mysql query to perform frequency ranking

Hi, am looking for a query which will perform frequency ranking, so that the record which has maximum occurances of supplied "key word" will be listed top in the result. my fields in the table are text and id. Can any one help me in this. Thanks in advance. ...

In mySQL, how do I return a list of grouped items limited to a certain number of groups + unique items.

Okay, so this one may be difficult but I will do my best to explain. Bear with me... I have a table with multiple columns as follows. ITEM_ID - GROUP_ID 1 - null 2 - null 3 - null 4 - 3 5 - 3 6 - 3 7 - 21 8 - 6 9 - ...