Select rows containing identical values in two columns

2007-11-16 Thread Stephen P. Fracek Jr.
I have a table that has a column with the id of the person that  
created the row.  In another column in the same row there is a column  
with the id of the person that modified that row.


Is there a way to write a SELECT statement that will return all the  
rows where the value in the creation column equals the value in the  
modification column?  I don't want to specify a specific id in either  
of the columns.


TIA

Stephen P. Fracek, Jr.
[EMAIL PROTECTED]




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



[5.0] Left Join Problem

2006-07-21 Thread Stephen P. Fracek, Jr.
I'm trying to upgrade from MySQL 4.1 to MySQL 5.0.

A query that works in MySQL 4.1 does not work in MySQL 5.0 and I'm at a loss
as to how to proceed.

SELECT tab_a.item1, tab_b.item2, tab_c.item3, tab_d.item4, tab_e.item5,
tab_f.item6 FROM db.tab_a, db.tab_e, db.tab_f LEFT JOIN db.tab_b ON tab_b.id
= tab_a.id LEFT JOIN db.tab_c ON tab_c.id = tab_a.id LEFT JOIN db.tab_d ON
tab_d.id = tab_a.id WHERE tab_a.id = 'value' AND tab_a.id2 = tab_e.id2 AND
tab_e.id3 = tab_f.id3 LIMIT 1;

The above query now generates this error:  Unknown column 'tab_a.id in 'on
clause'.  Placing parentheses around the ON clause, LEFT JOIN db.tab_b ON
(tab_b.id = tab_a.id) does not work.

However, splitting the original query apart and grouping the Left Joins in
one query and the regular joins in another query does NOT generates any
errors:

SELECT tab_a.item1, tab_b.item2, tab_c.item3, tab_d.item4 FROM db.tab_a LEFT
JOIN db.tab_b ON tab_b.id = tab_a.id LEFT JOIN db.tab_c ON tab_c.id =
tab_a.id LEFT JOIN db.tab_d ON tab_d.id = tab_a.id WHERE tab_a.id = 'value'
LIMIT 1; - this is ok

AND

SELECT tab_a.item1, tab_e.item5, tab_f.item6 FROM db.tab_a, db.tab_e,
db.tab_f WHERE tab_a.id = 'value' AND tab_a.id2 = tab_e.id2 AND tab_e.id3 =
tab_f.id3 LIMIT 1; - this is ok

Why doesn't the original query work in MySQL 5.0?  What do I need to do to
make it work?

TIA

Stephen P. Fracek, Jr.
[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: [5.0] Left Join Problem

2006-07-21 Thread Stephen P. Fracek, Jr.
On 2006-07-21 1:01 PM, Gerald L. Clark [EMAIL PROTECTED]
wrote:


 It is a join precedence issue. Use INNER Join instead of a comma.


Thanks Gerald.  

Paul DuBois' polite suggestion to read the manual helped.  Upon re-reading
the section about the change in precedence with
the comma operator and the join, I realized there was a
simple fix and that I had misinterpreted the section on the first read.

The revised query works.

Stephen P. Fracek, Jr.
[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Optimizing DISTINCT searches

2006-05-01 Thread Stephen P. Fracek, Jr.
Several of my DISTINCT searches are frequently showing up in the slow query
log.  These queries use multiple table joins.  Using EXPLAIN shows that the
queries are using the appropriate keys, as far as I know.  Are DISTINCT
searches using multiple joins slow?

TIA.

Stephen P. Fracek, Jr.
[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



FW: Optimizing DISTINCT searches

2006-05-01 Thread Stephen P. Fracek, Jr.
On 2006-05-01 11:55 AM, Robert DiFalco [EMAIL PROTECTED] wrote:

 Well, normally a DISTINCT has to do a type of sort and is slower than
 non-DISTINCT queries. Each field of the result set is considered in the
 DISTINCT logic. Can you modify the query so that it does not require the
 DISTINCT? Can you post the query?

Robert -

Query:  SELECT DISTINCT Project.Site_ID, Site, Status, Type FROM Project,
Site WHERE Site.Site_ID = Project.Site_ID ORDER BY Site;

Site is the site name, Status and Type contain additional information about
the site, and Site_ID is the unique site id.

The Project table contains among other things a list of sites where the
projects are being done.

The results of this query are supposed to be a non-duplicated list of sites
that are associated with at least one project.

As the number of projects and sites have increased, this query is now
frequently in the slow query log.
 

Stephen P. Fracek, Jr.
[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Optimizing DISTINCT searches

2006-05-01 Thread Stephen P. Fracek, Jr.
On 2006-05-01 1:14 PM, Robert DiFalco [EMAIL PROTECTED] wrote:

 Would you need the DISTINCT if you change the query like so?
 
 SELECT Site.Site_ID, Site, Status, Type
 FROM Site 
 JOIN Project ON Site.Site_ID = Project.Site_ID
 ORDER BY Site; 
 
 You may also want to just try your initial query without the distinct to
 see if that is the issue. Also, do you have an index on the Site
 column? The issue with this query is that you are pretty much selecting
 everything from the Project table.

Robert -

Your query doesn't work - it finds ALL the rows in Project table and hence
repeats the sites..

I do have an index on the Site table, it is the Site_ID.  The
Project.Site_ID is also indexed.

Stephen P. Fracek, Jr.
[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



MySQLHotCopy Error

2005-09-10 Thread Stephen P. Fracek, Jr.
We're having a problem with MySQLHotCopy.  It has worked flawlessly in the
past but now we're getting an error message similar to this:

Dumping database... DBD::mysql::db do failed: Can't find file:
'./file.frm' (errno: 24) at /usr/local/mysql/bin/mysqlhotcopy line 468.
Deleting previous 'old' hotcopy directory ('mydirectory')
Existing hotcopy directory renamed to '/mydirectory/db_name_old'
done.

The frm file it can't find varies with each attempt to use MySQLHotCopy.
The files are there.  We've flushed, optimized, and repaired all the tables
in the database without any luck.  The db appears to be working fine.

MySQLHotCopy works ok with other databases on this server.

MySQL 4.0.23

Server:  Mac OSX Server 10.3.8 dual 1.33 Ghz PPC G4 with 2 GB SDRAM

DB has 274 tables with 1.6 million records.  DB size is 400 MB.

Any insights would be greatly appreciated.

TIA

Stephen P. Fracek, Jr.
[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]