Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Sql Returning Too Many Results On JOIN


I have three tables which I'm joining...

AGENTS
========
agent_id
commission
promo_code

AGENT_PAYMENTS
==============
payment_id
agent_id
amount

SALES
========
sale_id
promo_code
status

I need to select all the sales info where an agent's promo code has been used (and the status of the sale is "C" (complete)). THe trouble is, the SQL I've used is doubling, trebling etc the sum of the payments made to an agent - this depends on how many results are returned for the number of sales... eg: 4 sales means the SUM is being multiplied by 4.

here's the SQL Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Query Not Returning Any Results
I can't get any results form my query:

SELECT * FROM userfile

There's only one record in the table  but I don't get nay results.

The query is written in PERL:

#!/usr/bin/perl -w

use CGI qw(param);
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header();

..........

Fulltext Returning Too Many Results
How do I get a fulltext search to return only records that contain all terms instead of records that contain any of the terms?

In other words, if I enter the search "blues clues" MySQL will only find records that contain the words "blues" AND "clues" without having to introduce special boolean search syntax.

Returning Results Without Duplicate Records
I have 2 tables with related data.
one table is for products. and the other orders. In orders table one product may appear several times.
Now if i wanted to return an array with the products being ordered I will get duplicates of each product.
How can I return the results showing the products ordered wirhout containg duplicate rows

Query Is Not Returning Desired Results.
My query is not returning desired results.
I want to structure my query to return the Post Subject, Post Text, and Poster. Instead, it is returning the correct Post Subject, correct Post Text, but the Poster is just repeating the username from the '$_POST[username]' variable. How can I alter the query to return the correct name?

the query
PHP

<?php$conn = mysql_connect( $domain, $user, $password ) or die("Err:Conn");$rs = mysql_select_db($db, $conn) or die("Err:Db");$sql = "SELECT `table_posts_text`.`post_subject`, `table_posts_text`.`post_text`, `table_users`.`username` FROM table_categories, table_forums, table_topics, table_posts, table_posts_text, table_users WHERE username='$_POST[student]' ANDcat_title='$_POST[category]' AND`table_categories`.`cat_id`=`table_forums`.`cat_id` AND `table_forums`.`forum_id`=`table_topics`.`forum_id` AND `table_topics`.`topic_id`=`table_posts`.`topic_id` AND `table_posts`.`post_id`=`table_posts_text`.`post_id`AND `table_topics`.`topic_poster`=`table_users`.`user_id`AND`table_posts`.`poster_id`=`table_users`.`user_id`ORDER BY `table_topics`.`topic_id`, `table_posts`.`post_id`";  $rs=mysql_query($sql,$conn);while($row=mysql_fetch_array($rs)){    echo($row['post_subject'] . $row['post_text'] . $row['username']);}?>


There are six tables involved:
1. table_categories (cat_id medint, cat_title varchar)
2. table_topics (topic_id medint, forum_id smallint topic_title varchar topic_poster medint)
3. table_forums (forum_id smallint, cat_id medint, forum_name varchar)
4. table_posts (post_id medint, topic_id medint, forum_id smallint, poster_id medint)
5. table_posts_text (post_id medint, post_subject varchar, post_text text)
6. table_users (user_id medint, username varchar)

Full Text Not Returning Any Results
I'm having some issues with my full text indexes in MySQL 3.23.58. I'm
using I have a table with a full text index on the 'content' column.
There are some words that are returning results just fine but others
that should return results aren't.

For example,

SELECT * FROM lift_content WHERE match(content) AGAINST('content')
returns results just fine.

SELECT * FROM lift_content WHERE match(content) AGAINST('gangs')
doesn't return any results when there are rows that have the word
'gangs' in it.

Any thoughts on why certain words aren't returning results when they
should, and aren't included in the stopword list?

Returning Stored Procedure Results
I've tried a million (okay, maybe a dozen) different techniques to try and get this stored procedure to work and I've failed every time. I'm passing a unique id into the stored procedure and want to get back the corresponding results when the logic is finished.

For example, I have:

[removed code]

I had no problem doing just one of the variable sets as I could do a SELECT and get all of the results back, but we need to do all three at once so that we're not having to reconnect from PHP each time. Any suggestions?

Two Similar Queries Returning Different Results.
I have two queries that get run. They are basically the same, except for one formats the results a bit. They both count 'referrals' and 'contracts'. I can't seem to figure out why the counts change. Code:

Returning 1 Tables Results From Two Table Query
I am executing a query which finds a criteria from certain records in table A and returns all values from table B if the criteria in table A is true. I want to return only the data from table B but can't find an easy way to do that? E.g the MySQL 'From' expression contains both tables.

Print All Mysql Results - So I Can Check What I'm Returning
i want to see all results from a sql query dumped on the browser page...

must be possible, just cant find the right command...

LEFT JOIN Returning NULL Values
I am trying to perform a LEFT JOIN on a table which may or may not have
matching rows.

If there are no matching rows, it returns NULL's for all the missing fields.

Is there anyway of returning the default values for that table instead of
NULL's, in a portable way?

My query currently looks like this:

SELECT i_product.name, i_product.price, `i_tax-rate`.rate
FROM i_product
LEFT JOIN `i_tax-rate` ON (`i_tax-rate`.`tax-rate-id` =
i_product.`tax-band-id`)
WHERE i_product.id = 123';

Join Vs. Inner Join Vs. Implied Join = Different Results ??
I SUM() only on the order table in all queries below. Here's a set of queries that I thought would/should yield the exact same results:

QUERY 1:
SELECT COUNT( o.orderID )
FROM order o
WHERE DATE( o.orderDATE ) = &#55614;&#57159;-01-04'
AND o.orderSTATUS = 300

yields 161

QUERY 2:
SELECT COUNT( o.orderID )
FROM order o
LEFT OUTER JOIN credit_card cc ON o.orderID = cc.orderID
WHERE DATE( o.orderDATE ) = &#55614;&#57159;-01-04'
AND o.orderSTATUS = 300

yields 175

QUERY 3:
SELECT COUNT( o.orderID )
FROM order o, credit_card cc
WHERE o.orderID = cc.orderID
AND DATE( o.orderDATE ) = &#55614;&#57159;-01-04'
AND o.orderSTATUS = 300

yields 157


Problem With Left Join And Count, Returning More Rows Than What It Should
Am having a problem with a query, strangely ...

PHP

SELECT *
FROM table1 AS mt
LEFT JOIN table2 AS pt ON mt.p_id = pt.p_id
WHERE my_field = 'somevalue'

Is returning a much bigger number (12 rows) for me, then what it should.

PHP

SELECT *
FROM table2
WHERE my_field = 'somevalue'

Is returning only 2 rows

How To Join Results ?
Is it possible to join results of the select query ?

So If I get data from two rows (firstname, secondname)Can I somehow join query results like this: firstname.secondname

Example:

QUERY: SELECT firstname,secondname FROM table;

RESULTS:
John.Doe
Mike.Monroe
Kate.Moss

Limit Inner Join Results ?
Is it possible to limit the results of an inner join or sub select ?
For example, let say that I have a table of countries and a talbe of cities:

Join Duplicated Results Issue
I have two tables, one is a catalogue of products and another one with media connected to the catalogue items. the media can be either 'main image' or an 'alternative product view'. I need to retrieve 4 products that are marked as live (c.status = &#391;') and their 4 corresponding main images (m.category = 'main') with no repeats on the products.

I have the following query:

SELECT DISTINCT c.id, c.category_id, c.title, c.description, m.filename, m.description, m.copyright
FROM catalogue c
LEFT JOIN media m
ON m.parent_id = c.id
WHERE c.status = &#391;'
AND m.category = 'main'
LIMIT 4
the problem I have is that some products have more than one 'main image' so this query is returning a duplicate product because it has two main images, even if the product only exists once on the catalogue..

Selecting Distinct Results In A Join
SELECT p.post_title
, p.post_name
, c.cat_name
, DATE_FORMAT(p.post_date, '%M %D, %Y') AS dateadded
FROM wp_posts AS p
LEFT JOIN wp_post2cat AS pc ON p.ID = pc.post_id
LEFT JOIN wp_categories AS c ON pc.category_id = c.cat_ID
WHERE MATCH(p.post_content, p.post_title)
AGAINST(TRIM('merchant') IN BOOLEAN MODE)
ORDER BY p.post_date DESC
I am doing a fulltext search on a Wordpress database. Some posts are in multiple categories. When using the above query I will get a result for every category a post is in. I don't want that. I have tried using distinct with no effect. The wp_categories has a row for each category a post is in and how I am joining it seems to be the culprit.

Join 3 Tables - Distinct Results
I've got a database that keeps track of sales of widgets. Each company
that belongs to my organiztion is to report their widget sales or no
sales every month.

There are several different types of widgets. Not all companies sell or
report all types of widgets.

We want to report how many companies have reported or not reported their
sales (ie. x companies of a possible y companies have reported sales
this month - y will always be the same - lets say 5).

Because of the way that sales are input, "big widgets" are reported in 2
different tables called widgets_a and widgets_b. If they don't have any
sales to report, they still report and it goes into a table called
no_reports. Each table has a couple of common fields - ManufacturerID
and OrderDate.

I can search all of the tables individually to find if a manufacturer
has reported -

SELECT DISTINCT ManufacturerID FROM widgets_a WHERE OrderDate >=
'2003-06-01' AND OrderDate <= '2003-06-30';

but I want to search through the 3 tables and find how many distinct
manufacturers have reported in the given month.

Join 3 Tables - Distinct Results
I've got a database that keeps track of sales of widgets. Each company
that belongs to my organiztion is to report their widget sales or no
sales every month.

There are several different types of widgets. Not all companies sell or
report all types of widgets.

We want to report how many companies have reported or not reported their
sales (ie. x companies of a possible y companies have reported sales
this month - y will always be the same - lets say 5).

Because of the way that sales are input, "big widgets" are reported in 2
different tables called widgets_a and widgets_b. If they don't have any
sales to report, they still report and it goes into a table called
no_reports. Each table has a couple of common fields - ManufacturerID
and OrderDate.

I can search all of the tables individually to find if a manufacturer
has reported -

SELECT DISTINCT ManufacturerID FROM widgets_a WHERE OrderDate >=
'2003-06-01' AND OrderDate <= '2003-06-30';

but I want to search through the 3 tables and find how many distinct
manufacturers have reported in the given month.

Join 3 Tables, Limit Results From 3rd Table
Yet again I have a query about joins and even though I keep reading I cannot find a solution for my problem that is relevant or that I understand.

I have 3 tables (I have shortened the number of fields to those that are relevant):

category:

Quote:

catid

product:

Quote:

prodid
catid
prodname




prodimgs:

Quote:

imgid
prodid
imgname

I can select all products per category and I can select all images per product, but where I am having the problem is selecting all products for one category and at the same time selecting all the images per product and limiting the number of images displayed to one without limiting the products to one.

I have tried various joins and tested a lot, getting different results but none of them are returning what I need.

Select all products for a category:

PHP

SELECT prodid, prodname FROM product WHERE catid='$this->catid'


Works fine.

Select all images per product per category and limit results of image to 1:

PHP

SELECT product.prodid, product.catid, product.prodname, prodimgs.imgname FROM product, prodimgs                WHERE product.catid ='$this->catid' AND prodimgs.prodid = product.prodid LIMIT 1


This returns only one product and one image per category despite there being more.

Using the same code as above but removing the limit I get a display of all images per product with the product name repeated over and over.

I know I need to use joins somehow but I have tried various ways and tested the sql but am always getting an error on the joins and I don't know how or where to put the limit so that it is only applied to the prodimgs table.

So what I want is:

1. User click on a category

2. On the next page all product names linked to the category are displayed, but once only.

3. Next to each product name, one image related to that product is to be displayed if an image is stored in the prodimgs table

Combining Results From Querying Two Join Tables
I'm using two queries to pull data from a two join tables and am looking for a way to get them into one result.

The first query is:
select group_concat(x) as genre_id, group_concat(y) as genre_name from (
select genres.id as x, genres.g_name as y from genres where id in (
select genre_id from genres_movies where movie_id = 70000103
)
) as tbl

+---------------------+---------------------------------------------------------+
| genre_id | genre_name |
| 864,131,813,191,321 | Documentary,Indie Documentaries,Political Documentaries |
+---------------------+---------------------------------------------------------+
The second is:
select group_concat(a) as director_id, group_concat(b) as director_name from (
select director.id as a, director.p_name as b from directors where id in (
select director_id from directors_movies where movie_id = 70000103
)
) as tbl2

+----------------------------+------------------------------------+
| director_id | director_name |
| 20006021,20063045,20063046 | Chris Smith,Dan Ollman,Sarah Price |
+----------------------------+------------------------------------+
Does anyone see a way to get something like this?
+---------------------+---------------------------------------------------------+----------------------------+------------------------------------+
| genre_id | genre_name | director_id | director_name |
| 864,131,813,191,321 | Documentary,Indie Documentaries,Political Documentaries | 20006021,20063045,20063046 | Chris Smith,Dan Ollman,Sarah Price |
+---------------------+---------------------------------------------------------+----------------------------+------------------------------------+

Left Join Producing Unexpected Results
The following SQL query is producing undesirable results.  What I am trying to do is get the ID of the people listed in the persons table, who are not on a given list, on the listtrack table.  The listtrack table has an entry for each Person_ID<->List_ID pairing.  I can find out easily who is on a given list, but it's finding who is not that is giving me bother.

SELECT people.PersonID
FROM people LEFT JOIN listtrack ON people.PersonID=listtrack.Person_ID
WHERE  (listtrack.List_ID<>4 Or listtrack.List_ID IS NULL)
AND people.Company Like '(none)'

Join Results From Select Multiple Statment
how I can join results from multiple queries in one result without geting a prodict of the tables

ex:
table1_Col1, table1_Col2, table1_Col3...table2_Col1, table2_Col2, table2_Col3...table3_Col1, table3_Col2, table3_Col3...
table1_Col1, table1_Col2, table1_Col3...table2_Col1, table2_Col2, table2_Col3...table3_Col1, table3_Col2, table3_Col3...
, , ...table2_Col1, table2_Col2, table2_Col3...table3_Col1, table3_Col2, table3_Col3...
, , ... , , ...table3_Col1, table3_Col2, table3_Col3...
, , ... , , ...table3_Col1, table3_Col2, table3_Col3...


using the 4.0 sql so no subqueries supported.

LEFT JOIN? RIGHT JOIN? Multiple JOIN?
Simplifying this down to its basics, I'm using LEFT JOIN in a query but I'm not getting the results I want.

The tables are:
table services
service_id
service_name

table services_provided
service_id
service_date (date field)
cust_id
service_quantity

I need to select ALL services from the services table, and the number of services provided (by a specific customer, in a specific time frame) from the services_provided table, so that I can generate a list that shows services provided by that customer in the specified period of time

The query:

SELECT service_date, service_name, service_quantity
FROM services
LEFT JOIN services_provided ON services_provided.service_id = services.service_id
WHERE cust_id = $cust_id
AND MONTH(service_date) = 10
AND YEAR(service_date) = 2007
GROUP BY service_id
ORDER BY service_id
(Aside: The date to be selected varies - it may be the whole year, or may be a selection of months,such as 1, 2 or 3. This is determined dynamically in the script. The cust_id is determined by which customer is logged in.)

I'm pretty sure that the left join as I have it should return all services, even if there's no corresponding entry in the services_provided table.

But because of the WHERE clause, I don't get a complete list of all services -- if the customer doesn't have any entries for a particular service, that service doesn't come up in my results.

Do I need to change how I'm joining the tables, or join them twice? I'm sure I could do this with a nested query, but I'm trying to avoid that.

Returning More That One Row From SP
I have 2 simple questions on stored procedures:

1) how do I return multiple rows?
DELIMITER //
CREATE PROCEDURE join_nary_relation() BEGIN
DECLARE c INT;

SELECT clanak_id FROM vidi_clanak_hardver INTO c;
END;
//
CALL join_nary_relation();

This fails:
ERROR 1172 (42000): Result consisted of more than one row

2) how do I return multiple columns?

As you see, I'd like to warp a SP around a SELECT in general case: a SELECT which returns a table with few rows and few columns. Is that possbile?

Returning Last Row
I need to return the last row in the table, I'm using auto_increment which is the 'priKey' column. 'beachName' is the name of the table , 'DATEOFFILE' is the column in the table that I need to return the last value for. Code:

Returning One Row
I'm working on a support ticket system. My two main tables are "tickets" and "ticket_messages". One ticket can have many ticket_messages. Ticket_messages have time stamps.
I need a query that will return all tickets with the ticket_message of the earliest time stamp, as opposed to pulling all ticket_messages for each ticket.
I'm having trouble digging up documentation or examples of this.
Here's a pseudo SQL statement that I'm trying to accomplish:

Code:


SELECT DISTINCT tm.subject, t.id, t.incident_date_time, t.create_date_time,
FROM tickets t
INNER JOIN ticket_messages tm ON tm.ticket_id = t.id
WHERE tm.id OF Min(tm.date_time_stamp)

Returning All Values
I'm sure this is a straight forward and obvious one:

I have this:

SELECT *
FROM tbl_contacts
WHERE con_Customer = "#URL.con_Customer#"
Which obviously when you pass a value over the url returns the relevant records.

How can I pass a value to the url which passes ALL the records back.
Is it something like ?con_customer='%'?

AVG Returning 0, Not Null
I'm writing a script to allow visitors to rate articles on my site. Sometimes a question does not apply to that particular article or a person is just too lazy to fill out the entire form. Either way, I'm passing NULL to the MySQL database if the question was not filled out.

I want to do averages for each article for each question I ask. The problem is that I'm getting 0 only when I use AVG () even though the MySQL site says that should return a null if empty. It is not.

I have a "control group" table pulling the same data without using AVG. Of course, every vote is visible, but it's clear that null is working properly in that example.

Here's is a shortened version of my

PHP

$queryA = " SELECT URL , AVG(Vote) ,AVG(A1) , AVG(A2) , AVG(A3)  FROM Galleries  GROUP BY URL  ";

$result = mysql_query($queryA) or die(mysql_error());

while($row = mysql_fetch_array($result)){
?>

<tr>

<td><?php echo $row['AVG(A1)']; ?>&nbsp;</td>
<td><?php echo $row['AVG(A2)']; ?>&nbsp;</td>
<td><?php echo $row['AVG(A3)']; ?>&nbsp;</td>
        
</tr>


<?
}
echo "</table>";


Any thoughts as to why AVG() would return 0 and not null when my database seams to be setup correctly?

Returning The Maximum Value From A SUM
Current query:

select sum(b) from db where dc=1 group by ba

returns:
510
764

I would like to just capture the MAX of this query.

Returning A One Value Average
I'm using PHP and MySQL, and am trying to return an average (songle value).
My code isn't working, and I'm getting confused between the mysql_fetch, here's my code:

$average = "SELECT AVG(overall) as overall, AVG(gameplay) as gameplay,
AVG(graphics) as graphics, AVG(sound) as sound FROM VIDEO_GAME_DETAIL
WHERE name=" .$row['name'];
$result = mysql_query($average);
$rating = mysql_fetch_array($result);

// down in an HTML table
echo "<td>" .$rating['overall']. "</td>";


$row['name'] is the name of a PC Game from the VIDEO_GAME table. In the VIDEO_GAME_DETAIL table I have reviews for many games, with ratings. My goal here is to average the different ratings (overall, gameplay, sounds and graphics) for a one game, and stick them with the main page that lists the games (1 row per game).

I get this following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Users/Marconi/Grad/lleccia/www/ISYG250/proj4/reviews.php on line 54

line 54 is $rating = mysql_fetch_array($result);

Returning Most Relevant
I have a table with a text field which contains the information for help files on my website.

Using full text searches i can return the most relevant results in order but is it possible to return the most relevant help text for each of the returned results.

I'm trying to show the user a sentence or two as a preview for the returned results.

How Returning Zero With COUNT()?
I have this table:

CREATE TABLE `people` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) NOT NULL default '',
`sex` char(1) NOT NULL default 'M',
`age` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM;

And I want knon how many Females and Males there are in three ranges of ages:
from 0 to 20, from 21 to 30 and over 31.
I've used COUNT() GROUP BY(sex) but the problem is that COUNT() doesn't return zero
but I want see the exact count of peoples of every ranges of age (for sex) including zero.

This is my query:

SELECT sex, ' < 20' AS range, COUNT(*) AS Num FROM people WHERE age between 0 and 20 GROUP BY(sex)
UNION
SELECT sex, '21-30' AS range, COUNT(*) AS Num FROM people WHERE age between 21 and 30 GROUP BY(sex)
UNION
SELECT sex, ' > 30' AS range, COUNT(*) AS Num FROM people WHERE age > 30 GROUP BY(sex)

How can I see zeros?

Returning The ID Of The Row Just Inserted...
I'm trying to amend my simple SP to return the unique 'auto-incremented' ID value to my SP as a client reference.

The SP inserts the new DB record and then should return the ID for that row...however when I run the PHP page that calls the SP, I get:

"ERROR: 1312 - PROCEDURE lead_collector.SPInsertEnquiry can't return a result set in the given context"

My SP is as follows: Code:

Last_insert_id() Returning 0
I was using a stored function to return the last inserted record id. With the latest version of the database that functions appears to have stopped working. Is there a fix or a work around that I can use for the meantime ?

Query Returning
I'm having a small problem with my news system. The query below should return the last 5 posts, who posted them, and the number of comments for each. It works fine, except the value comments_count is returning is 7 times what it should actually be.

Returning To The Community
Recently the community helped me immensly when I had a problem with my SQL and the server, I can only feel indebted (is there such a word?) to them for their help.

Last_insert_id Returning 0
Im trying to something like the following:

INSERT INTO foo (auto,text)
VALUES(NULL,'text'); # generate ID by inserting NULL
INSERT INTO foo2 (id,text)
VALUES(LAST_INSERT_ID(),'text');

The first insert goes ok and a record in foo is created, but the id inserted into foo2 is 0 and thats not right.

Returning A Percentage
is it possable to return ONLY 20% percent of the overall possable returns in a query? e.g. i have 100 possable returns and i only want 20% of them. So i'd receive 20 returns.

What i'm trying to do exactly is return the latest 30 entries and then the next 20% of the possable entries. i'm working with a database that has thousands of possable returns but i don't want all of them.

Returning New Columns
I have data in my SQL table like this:
(it goes like this to March 2008)

And I would like MySQL to return the same data but with this structure:

Is there any possible way to build a query that returns the data ordered in that way? That will really help me to build the application I need just by running through the results.I've been trying UNION, inner SELECTS and many other stuff without any good result. Just wondering if this is possible.

Returning A Field
It's difficult to explain what I'm trying to do, but this should help;

name | new article |

Ross | 1
Ross | 1
James | 1
Jeff | 1
Ross | 1

If this is the result of a query to select all the names/new article columns from a database where the new article column equals 1, how would I then return the name 'Ross' as the person with most new articles

Syntax Returning
i have a database on the follow format:

city, status, status_action


and for example i want to return peoples that have the status equal to 1 or 3 and status action equal to 1 or 3 from the city NY

so i am using the follow query:
city = 'NY' AND (status = 1 or status = 3) AND (status_action = 1 or status_action = 3)

but it dont return me the right value, it always give for example status equal 1 of everyone and ignore status 3

i have tryed to use AND aswell and i go no return.

Returning Msg From Stored Procedures
I`m learning how to use SP in MySQL and have some doubts about returning msg from SP. I`ve done sth like this:

SQL
DELIMITER $$ 
DROP PROCEDURE IF EXISTS `site`.`addContact` $$CREATE DEFINER=`root`@`localhost` PROCEDURE `addContact`(IN c_type VARCHAR(30)) 
BEGIN 
  DECLARE msg VARCHAR(100); 
  IF TRIM(c_type)<>'' THEN 
    IF (SELECT COUNT(*) FROM contacts WHERE `type`=c_type)=0 THEN      INSERT INTO `contacts` (type) VALUES (c_type);      SET msg='Successfuly added'    ELSE      SET msg='Already exists'    END IF; 
  ELSE    SET msg='Type name must be provided.'  END IF; 
  SELECT msg; 
END $$ 
DELIMITER ;

SP returns always one msg and it`s easy to use it later in app code i.e. PHP.
I`d like to ask if this aproach (with select returning msg) is acceptible? Or maybe I should use OUTPUT variable inside SP to get such info?

Returning The Automatic ID On Insert ?
Is it possible to return the auto_increment ID on inserting a row ?

It would save me alot of hassle so i don't have to do another query to get the ID

+ i'd have problems getting the ID of a row without the ID to say 'where pic_id = $id'. Then again i could just do 'where pic_created = $time AND user_id = $uid'

Subquery In IN() Not Returning All Possible Values
I'm sure there is some silly little mistake in here somewhere, but I can't find it. This is my first stab at subqueries, so I'm not at all surprised that I'm not getting the correct results.....

Returning More Than One Column In A Variable
How do you return three columns with dashes in between them as one variable

Like in PHP, you'd do

PHP

$dob = $day."-".$month."-".$year;

Like...

i.dob_day + "-" + i.dob_month + "-" + i.dob_year as dob
That obviously doesn't work, but you get the idea.

Returning Every Saturday Between Two Dates?
Having a major mental block with this, and was wondering if anyone can help me?

Basically I want to create query which will return every occurence of a Saturday between two dates.

Looking at the the DAYOFWEEK function, it doesn't appear that you can only provide it with a specific date. The only other way round that I could think of is by having a prepopulated table with all dates within a year and the actual date occurence.

I was hoping to do this on the fly, as the query would be used as part of trigger.

Returning Row Id For Added Values
This is probably a simple problem, but I don't know what term describes it so I've had trouble searching for a solution.

I have a table with an automatically incrementing primary key that I am adding data to. I would like to be able to return the row numbr (primary key) of the row to which the new data is being inserted.

Its Returning A Value That Doesnt Exist
Okay here is the deal. I am running a query to find out if there is an ID in my table that has a case number that matches the one being submitted. If there isnt once its should step into an if statement that would submit a number of records. Otherwise it should jump to the else statement.

I the problem comes from: the query keeps returning "Record id#2" but there is no record matching the case number being submited from the form.

if( isset($_POST['Submit'])){ //Begin If statement logic
$resultcheck = mysql_query("SELECT * FROM submissions WHERE wfmcase = " . $_POST['wfmc']) or die(mysql_error()); //Query string to test if wfmcase was already submitted
echo "Sucess, form varibles have been passed.<br />";
echo "Resultcheck query results: $resultcheck <br />";

if ($resultcheck == ""){ //Checks to see if the query was empty.
echo "There are no duplicate case escalations pending. <br />";

I added the echo statement so that i could see how far it was getting through the script. It dies after printing the varible $resultcheck which gives "Record id#2". It never enters the 2nd if statement because for what ever reason the query has the "record #id2" in it... What is causing this? I have verfied that there is no case that matches the one coming from the form and i get the same error.

Returning Top 5 Tags For An Item
System Info:
RedHat Linux 9 (text only)
Mysql 3

When I execute mysql from the command line I receive an error:

"error 2002: Mysql cannot connect to socket /var/lib/mysql.sock"

(or something similar) - the socket was definately not
"/tmp/mysql.sock"

It was installed by the RedHat 9 installer. Do I have to edit some
configuration file.


Copyright © 2005-08 www.BigResource.com, All rights reserved