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




SUM Query And Comparing Values In WHERE Clause...


Here is my query:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Comparing String Values In Two Different Columns
I am trying to do a string comparison between two columns located in two different tables. I tried the following SQL statement and it didn't work. This string comparison is for updating foreign keys in the referencing table.

sn-table (referencing)
e-table(referenced)

update sn left join e using(id)
set sn.Eid=e.id
where sn.name like e.name;

Although the command runs fine, it doe not produce the desired outcome!

I've seen SQL statements where comparison with a literal string works:

...
...
where sn.name like 'TX';

I want to compare variables not literals. I am trying to find a partial match between name on sn and name on e and then update FK in sn using corresponding id from table e.

Query Help, Comparing Rows
Suppose I have the following data:

+----+----------+-----+-----+-----+-----+-----+-----+-----+
| Id | Time | Sun | Mon | Tue | Wed | Thu | Fri | Sat |
+----+----------+-----+-----+-----+-----+-----+-----+-----+
| 11 | 11:20:00 | F | T | T | T | F | F | F |
| 12 | 11:45:00 | F | T | T | T | F | F | F |
| 14 | 12:10:00 | F | T | T | T | F | F | F |
| 15 | 12:35:00 | F | T | T | T | T | T | F |
| 17 | 13:00:00 | F | T | T | T | T | T | T |
| 18 | 13:25:00 | F | T | T | T | T | T | T |
| 19 | 13:50:00 | F | T | T | T | T | T | T |
| 20 | 11:28:00 | F | T | T | T | T | T | F |
| 21 | 11:53:00 | F | T | T | T | T | T | F |
| 22 | 12:18:00 | F | T | T | T | T | T | F |
+----+----------+-----+-----+-----+-----+-----+-----+-----+
I would like to output the data by day pattern. I need some way to determine that in the above table, Mon-Wed is the same, Thu-Fri is the same and Saturday and Sunday are unique.

Comparing Dates Y, M, D , Time In Sql Query
ok.. ive finally got my nice little calender setup to output my dates

now

how do i query my database

for example ive got 2 variables
$startdate = 2006-1-1 00:00:01
$enddate = 2006-1-1 23:59:59

these represent the 1st and last second of the first of january 2006

i have a cell in my table (table called challenges) ( cell called time) that contains a date in the same format for each entry

how do i get all the entries between the start time and the end time..

can i use less than < and more than > as these are not really integar values

the column type is datetime but there is also another column of type datetime

IN Clause For Select Query
Can someone help with query syntax regarding IN/EXISTS..

I'm trying to do this:

insert into table2 (field1) select field1 from table1 where field1 not in
(select field1 from table2)
delete from table1 where field1 in (select field1 from table2)

1. Insert field1 from table1 into table2 if it doesn't already exist
there...
2. Once moved, delete from table1.

Any help would be greatly appreciated.

SQL Query JOIN And LIKE Clause
I need to run a query which uses a like query like the one below, no problem:

SELECT * FROM footballers WHERE sname LIKE '%$criteria%'

however, if I want to join two tables and still use the LIKE clause how would the syntax look??

My guess below was incorrect. any help would be appreciated. thank you

WHERE sname LIKE '%$criteria%' AND (footballers.footballerID = PremTeams.footballerID)

IN Clause For Select Query
Can someone help with query syntax regarding IN/EXISTS..

I'm trying to do this:

insert into table2 (field1) select field1 from table1 where field1 not in
(select field1 from table2)
delete from table1 where field1 in (select field1 from table2)

1. Insert field1 from table1 into table2 if it doesn't already exist
there...
2. Once moved, delete from table1.

Which Query Is Used For Minus Clause
Can u give me the ans which query is used for minus clause. in MySql?

Where Clause In Select Query
I have this query atm: SELECT postid, body, posttime, commentcount FROM nz_posts WHERE sections = ':7:' ORDER BY 'posttime' DESC LIMIT 0, 5

this works, but "sections" can have something like ":7: :8:", ":4: :7:", etc... all the numbers are between : and there can be one or many numbers (all diferent).

I want to select all the rows that has :7: in the sections field.

What Query To Check If Any Rows Exist Satisfying WHERE Clause?
I'm looking for a query that will check if any rows exists in a table according to a WHERE condition. I know I can use COUNT(*) but then mysql will do unnecessary task of counting all the rows whereas I just need true or false. So far I did this:

SELECT COUNT(*) AS exists FROM mytable WHERE ...
Sometimes I just select the first row and check later in php how many rows have been returned:

SELECT some_col FROM mytable WHERE ... LIMIT 1
But I cannot do this check (or can I?) in sql alone and I have problems when I want to use this in a subquery, for example:

SELECT id,
name,
(SELECT COUNT(*) FROM mytable WHERE ...) AS exists
FROM othertable
WHERE surname='xxx'
Can I do the same without using COUNT(*)? I would like a query that returns 0 or NULL if no rows were found, or 1 (or some other value) if 1 or more rows were found.

Reference To Table Alias In From Clause To Be Used By Subquery InSelect Clause
I am using 5.0.26-NT on Windows 2000.

I have need to use a reference in the outer from clause in a subquery in
the select clause. Consider the following example:

Select (select b.baitID from b where b.entrydate curdate()) as
wantedBaitIDs from bait_tbl b;

My actual need is more complex than this as part of it is a rough cross
tab. If I try to define the table in the alias, not only do I lose
whatever benefits there are in the particular join I would use in the
outer from clause but would also require the join to be defined in each
subquery, requiring it to be examined each time it is used.

To be absolutely clear, in this example I want to use bait_tbl with the
alias of b in the subquery. In my actual query I reference the same
table twice with a different join set for each. I need to reference a
particular alias as that has the join set I need.

How To Sum Two Aliased Values In A Query
I need to sum two aliased values in a query in order to order the results.

The query looks like this:

Distinct Values In Mysql Query
I have mysql query but i am not sure about it,bcoz it return many rows..
I want like distinct values from three tables with ic number.
Which is posted by user...

"SELECT distinct loguser.icnumber,access.acccode,dealerdtl.name,loguser.fullname,access.period,loguser.staffcode,
DATE_FORMAT(access.actdate, '%d-%m-%Y ')As formatteddate1,
DATE_FORMAT(loguser.creationdate, '%d-%m-%Y %H:%i:%s')As formatteddate
FROM dealerdtl,loguser,access where access.icnumber=loguser.icnumber AND loguser.icnumber = '$custic'";
This query return many rows i dont know why, i want only one row which is
inserted by the user as customer id.

Reference To Already Retrieved Values In Query
As a simple example, say there is table 'namelist' with column 'names'
as char(20). I would like to do something akin to:

select namelist.names as mynames, left(mynames,2) as initials;

In this example, I could just do left(namelist.names,2), but in more
complex cases a value retrieved may have had a more complex logic behind
it, e.g., if a bunch of nested if() statements. It would seem logical
that if a value is already retrieved then I should be able to refer to
it within the same query, assuming that the original value does not need
to be recalculated. I know I could use a view to do this, but it adds
another layer of complexity, and I am not sure that the values would not
be recalculated each time the value is needed.

If someone could point out to me the correct terminology for this kind
of thing I believe I should then be able to look up the information
myself. My efforts to find this information on google and the mysql
website were unsuccessful.

Query For Counting Unique Values
I'm trying to find out if I can construct a query to MySQL that will return the number of unique values in a given column.  The reason is because I have a column that just contains just the YEAR of a given report.  I want to see how many different values populate the YEAR column through the entire query result so I know how many tables to render on screen (one table for each year).

NULL Values In SELECT Query
I need to know how to push null values to the bottom of a query sorted by ASC.  I know if you sort by DESC the null values are placed last.  How can I push the null values to the end of a query while still sorting using ASC?  Anyone?

Accumulating Values Inside A Query
I only have experience of simple queries, and this one is a bit beyond me. I've done some research, and I think it might be possible to do within a single query, but I'm not sure.

I have a single table. It contains columns (among others): date, number. I want to produce a table of DATE, and new_number_count, where 'new_number_count' is the number of numbers on day with date DATE that do not have rows on previous DATEs.

For example, if this is my table:

Update Query Where Values Will Come From Other Table
I'm creating an update query which the value will come from another table.

I have here my current query which unfortunately makes the system hangs. Probably because of the query itself is not properly coded.

update boxes b inner join messages m
on b.ctnnumber = m.ctnno
set b.consigneerecv = m.CName,
b.consigneerecvdate = m.DateRcv,
b.phrecventered = "Y",
b.PhilStatus = "delivered",
b.prevreleasestatus = b.releasestatus,
b.releasestatus = "delivered",
b.PhilStatusDate = m.smsrecvdate,
b.phdelprice = "0.00",
b.phdelamt = "0.00",
b.recvrelation = m.Relation,
b.APRecventered = m.smsRecvDate
where b.consigneerecv = ''
or b.consigneerecv = 'NA'
or b.consigneerecv is null;

I'm thinking revising it so that it will not cause the system to hang but I don't know how. Guys please help me with this one. I also have this another idea which probably will not work. My idea was something like this:

Update table1 set table1.column1 = (select table2.column1 where table2.column1 = table1.column1),
table1.column2 = (select table2.column2 where table2.column1 = table1.column1), .....

How To Generate Sequence Values During Query
I have query like below:

SELECT part_no,part_nm,qty FROM tb_stok_out ORDER BY part_no

as result:

part_no part_nm qty

aaa asdfd 3
abab sdfsdf 4
abab adfdf 5

Is it possible in mysql to generate sequence number using query, so the result will be like below :

1 aaa asdfd 3
2 abab sdfsdf 4
3 abab adfdf 5
... etc

Difficult Query - Need To Group Results By Id And Sum Values
I have got the meat of this query done but I am facing a problem. I am doing a VAT analysis whereby I have every shoe that is over size 7 I pay tax on and every shoe below that I don't pay tax on. I also pay tax on accessories.

What I want the query to return is this:

Date | ShopperID | VATable Amount | Non VATable Amount|
2006-3-1 | 802135 | 146.95 | 54.00 |

Basically each shopperID will only appear once which is why I am grouping the results (which I have managed). But I also need it to total up all the VATable amounts that it finds too for both the fields on the right above.

I can get the date and order number without difficulty and I have managed to get the data like this so far where I have the same ShopperID where a shopper has bought more than 1 product:

+------------+----------+-----------------+---------------------+
| Date | ShopperID| VATable Amount | Non VATable Amount |
+------------+----------+------------+---------------+
| 2006-09-04 | 805284 | 0 | 64.00 |
| 2006-09-04 | 805287 | 2.95 | 0 | <-- Here a
| 2006-09-04 | 805287 | 3.25 | 0 | customer has
| 2006-09-04 | 805287 | 3.45 | 0 | bought 4 products
| 2006-09-04 | 805287 | 4.95 | 0 | - I need total
| 2006-09-04 | 805327 | 0 | 53.95 | under each
| 2006-09-04 | 805335 | 0 | 58.95 | ShopperID
| 2006-09-04 | 805414 | 0 | 64.95 |
| 2006-09-04 | 805414 | 3.25 | 0 |
| 2006-09-04 | 805414 | 0 | 64.00 |
| 2006-09-04 | 805414 | 0 | 69.00 |
| 2006-09-04 | 805423 | 0 | 64.95 |
| 2006-09-04 | 805423 | 0 | 69.00 |
| 2006-09-04 | 805423 | 0 | 64.00 |
| 2006-09-04 | 805423 | 3.25 | 0 |
+------------+-----------+----------------+--------------------+

Heres the query currently getting these results (without the GROUP BY ShopperID).

SELECT Date,orders.ShopperID,
CASE
WHEN SUBSTRING_INDEX(Product,',',-1) REGEXP '( )?(UK)?( )?[^1-9][7-9]( )?('
THEN items_ordered.price -- If size 7 or above add price
WHEN SUBSTRING_INDEX(Product,',',-1) REGEXP '( )?(UK)?( )?[^1-9]10( )?('
THEN items_ordered.price -- If size 7 or above add price
WHEN SUBSTRING_INDEX(Product,',',-1) REGEXP '( )?(UK)?( )?[^1-9]11( )?('
THEN items_ordered.price -- If size 7 or above add price
WHEN SUBSTRING_INDEX(Product,',',1) REGEXP 'Insole|Helmet|Laces|Wheels|Removal|Protection|Bag'
THEN items_ordered.price -- If it is an accessory add VAT
ELSE 0
END AS 'VATable Amount',

CASE
WHEN SUBSTRING_INDEX(Product,',',-1) REGEXP '( )?( )?(Kids)?( )?( )?(UK)?( )?( )?(Kids)?( )?( )?[^1-9][1|2|3|4|5|6]( )?('
THEN items_ordered.price -- If size 1 - 6 add price to other column
WHEN SUBSTRING_INDEX(Product,',',-1) REGEXP '( )?( )?(UK)?( )?( )?Kids( )?( )?(UK)?( )?12|13( )?( )?('
THEN items_ordered.price -- If size kids 12/13 add price to other column
ELSE 0
END AS 'Non VATable Amount'
FROM items_ordered,orders WHERE (items_ordered.ShopperID = orders.ShopperID) AND (Date >= &#55614;&#57158;-1-30') AND (Date <=

&#55614;&#57158;-9-31');

How Can I Return (x,y) Query Values To Create A Graph?
Im trying to build a graph of values from a counterTable. (Eg - get a list of how many times a page was requested in a week period with each y value being a day).

If the table looks like this...

A Query To Select A Column When A Percentage Of Values Non Zero?
I wounder whether some of the experts out there might be able to help
me with a problem I'm having. I do not know whether this is possible or
not...

I have a large table of stock price data which is straight-forward
enought. I can select prices based on a ticker and date ranges.
However, what I'd like to do is to select prices only when, say 75% of
them are non-zero (with the goal of eliminating new/suspended/delisted
stocks).

Of course I could just select where price > 0, but then I might get
only a few rows where this is the case. What I would like to do is
always get the full date range of prices, but only if >75% are there.

How Can I Return (x,y) Query Values To Create A Graph?
Im trying to build a graph of values from a counterTable. (Eg - get a list of how many times a page was requested in a week period with each y value being a day).

If the table looks like this...

Query To Insert 2 Foreign Key Values In Table
I want to insert 2 foreign key values along with some other value into table ....

Using A Limit Clause, But Return The Number Of Rows Of The Query Without The Limit
I have heard of a cool feature that mysql provides a way to return the number of rows of an sql statement that contains a LIMIT as if the LIMIT had not been there.

I search the mysql manual, but could not find anything.

Showing Query Result With Default Values When No Data Available
I have a scenario that user can ask for certain data say income & expense for last 3 months on monthly basis. I have wrote following query which works well but it has an issue:

Let say I have asked for data of FEB 2007, JAN 2007, DEC 2006 using the following query it shows me correct result when all three months have some data but it doesn't show me the desired result when you don't have data in one or more months.

Any suggestion to get result when there is no data:

Truncated Time Values Using TIMEDIFF With ORDER BY Query
I'm using the following query:

SELECT glider, timestamp, TIMEDIFF(timestamp, UTC_TIMESTAMP()) AS last_contact
FROM surfacings
INNER JOIN
(SELECT MAX(timestamp) AS most_recent FROM surfacings GROUP BY glider)
AS tmp
WHERE surfacings.timestamp = tmp.most_recent;

to calculate the amount of time that has elapsed since the last inserted timestamp for each glider. Everything works fine: ....

Comparing Age
So the birthdays in my MySQL table are in a column called DOB and in the format of say: March 8 1985.
Now i have my own PHP function that will convert that to a nice numerical value of age relative to today, which is perfect. it is called getAge(). However, i can't seem to be able to parse an SQL query with that function inside...is there any way to parse my own PHP functions inside an SQL query?

Comparing
I'm currently working with two tables; A scheduling table and a document table. Basically I'm trying to make a query that says this -- "give me everything from this month and day in the Document table that's not in the Schedule"


Comparing A Csv To A Db Table
How would I go about comparing values in a CSV file to a table in the database, and then removing any rows where that value (an email address) matches? Is this something I can do in phpMySQL or will I need to create a separate PHP script or something?

I maintain a mailing list using something called ListMessenger. It's a great web application, but the one major drawback is that it doesn't have a way to handle bounces. Over the course of 5-6 years, I'm now up to around 800-900 bounced emails every time I send out a newsletter.

I'd really like to clean up the list and I was able to extract all the bounced address from my email client. I'm just not sure how to do it. I actually have an idea of what needs to be done... it's more the actual code to make it happen that I'm not sure of.

I'm thinking it would be something like this:

1. Open csv file and read values into an array
2. Run a SQL statement that removes any rows from the "users" table if the "email_address" field matches any of the addresses in the array.

Any help would be greatly appreciated. I can get into more specifics as far as the table/column names and stuff,

Comparing Tables
I have a query that produces a list of names of people who have completed a certain course. I want to be able to run a report which can show who has not completed this course. The code I have attached below just returns the same resut as those who have sat the course.

SELECT distinct pps_principals.name as pname, pps_principals.login, pps_scos.name, pps_transcripts.score, pps_transcripts.max_score, pps_transcripts.status
FROM (dbo.PPS_SCOS JOIN dbo.PPS_TRANSCRIPTS ON dbo.PPS_SCOS.SCO_ID = dbo.PPS_TRANSCRIPTS.SCO_ID)
JOIN dbo.PPS_PRINCIPALS ON dbo.PPS_TRANSCRIPTS.PRINCIPAL_ID = dbo.PPS_PRINCIPALS.PRINCIPAL_ID
where pps_transcripts.date_created between &#55614;&#57158;-12-01' and &#55614;&#57158;-12-31'
AND PPS_TRANSCRIPTS.STATUS like '[PCF]'
and pps_scos.name = 'COURSE1'
or pps_scos.name = 'COURSE1.1'
or pps_scos.name = 'COURSE1.2'
AND PPS_TRANSCRIPTS.TICKET not like 'l-%'
and pps_principals.name not in (
SELECT distinct pps_principals.name FROM (dbo.PPS_SCOS JOIN dbo.PPS_TRANSCRIPTS ON dbo.PPS_SCOS.SCO_ID = dbo.PPS_TRANSCRIPTS.SCO_ID)
JOIN dbo.PPS_PRINCIPALS ON dbo.PPS_TRANSCRIPTS.PRINCIPAL_ID = dbo.PPS_PRINCIPALS.PRINCIPAL_ID
where pps_transcripts.date_created between &#55614;&#57158;-12-01' and &#55614;&#57158;-12-31'
AND PPS_TRANSCRIPTS.STATUS like '[PCF]'
and pps_scos.name = 'COURSE1'
or pps_scos.name = 'COURSE1.1'
or pps_scos.name = 'COURSE1.2' )
AND PPS_TRANSCRIPTS.TICKET not like 'l-%'

Comparing Dates?
i have an 8 digit date string that i want to compare to a column of type 'date' in
a MySQL db. the 8 digit string is in the format 'CCYYMMDD'. the question is: do
i need to put it into the 'CCYY-MM-DD' format in order to get correct output from
the datediff function, or can i simply leave it how it is?

Comparing Dates
I have a problem with me. I am describing the whole situation. I have a table, the structure of the table is as follows:

Table Name: Announcement
FieldName Data Type(Size)
Announcement Varchar(50)
St_Hr Decimal(10,0)
St_Min Decimal(10,0)
St_Day Decimal(10,0)
St_Mon Decimal(10,0)
St_Year Decimal(10,0)
End_Hr Decimal(10,0)
End_Min Decimal(10,0)
End_Day Decimal(10,0)
End_Mon Decimal(10,0)
End_Year Decimal(10,0)

The data stored is:
Test Announcement,10,20,6,10,2005,11,0,8,10,2005

Now, I have to write a query to retrive announcements after filtering them as per the mentioned Starting and Ending Date & Time. The condition should use the local date and time.

Comparing Versions Of Sql
I'm taking up a new position and have never used sql before although use
and code in lots of other languages. When doing a bit of survey I find
many many versions of commercial and public versions of sql. Can anyone
tell me if the syntax is generally similar or are they completely
different. If I invest time learning mysql on XP or Linux will that be
useful if I end up using something like Oracle later on? The only one I
would avoid is MS.... like things that work occasionally.

Comparing Strings
I have a lot of records in a table named in this pattern "this text is the same.r01 someText (001/100)", "this text is the same.r01 someText (002/100)", "this text is the same.r02 someText (003/100)" etc.

The idea is that i want to automate the process of recognizing the files belonging to the same file(.r02 in this case), and then set a value which shows that is belongs to a certain fileID in another table.

The problem is that i have no idea what would be the best way to do this. My initial guess is that i would have to use a trigger and a LIKE clause comparing the "this text is the same.r02" part of the string, to see if it already exists in the database. If it does, i have to mark it as belonging to the same file.

I guess using a LIKE clause would be very slow, and the amount of records will grow quite big(millions of rows).

Comparing Tables
tablename: leftfile
Fieldname: leftword
Data: bbb
ccc
xxx
zzz

Tablename: rightfile
Fieldname: rightword
Data aaa
bbb
ccc
ddd
eee

I want to know which records in table rightfile do not match records in leftfile.
My assumption was that this should be possible with:
select rightword from rightfile, leftfile where rightword not like leftword.
The opposite query, which is finding a match between records works spot on:
select rightword from rightfile,leftfile where rightword = leftword.

Two questions:
1. What would be the proper method of achieving the desired result (all records from rightfile that do not have an equal record in leftfile)

2. I must be missing something important in my thinking. Why would my method not work?

Comparing Two Fields With LIKE
Here's the sql:

SELECT *
FROM boxer.lpars a, boxer.libraries b
WHERE b.lpars LIKE '%a.lpar%'
AND a.deleted = 0
ORDER BY node, lpar

b.lpars will commonly look like: "WIN1#WIN2#WIN3#WIN4#"
a.lpar will commonly look like: "WIN1"

When I run this query I get zero matches. What do I need to do to match fields using LIKE?

Comparing Versions Of Sql
I'm taking up a new position and have never used sql before although use
and code in lots of other languages. When doing a bit of survey I find
many many versions of commercial and public versions of sql. Can anyone
tell me if the syntax is generally similar or are they completely
different. If I invest time learning mysql on XP or Linux will that be
useful if I end up using something like Oracle later on? The only one I
would avoid is MS.like things that work occasionally.

Comparing Two Table
I have two tables:

CREATE TABLE `FootballerScore` (
`footballerID` mediumint(4) NOT NULL default '0',
`GameWeekID` mediumint(4) NOT NULL default '0',
`GameRuleID` mediumint(4) NOT NULL default '0',
`Goals` mediumint(4) NOT NULL default '0',
`Assists` mediumint(4) NOT NULL default '0',
`CleanSheets` mediumint(4) NOT NULL default '0',
`YellCards` mediumint(4) NOT NULL default '0',
`RedCards` mediumint(4) NOT NULL default '0',
`WeeklyScore` mediumint(4) NOT NULL default '0',
`AccScore` mediumint(6) NOT NULL default '0',
PRIMARY KEY (`footballerID`,`GameWeekID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `footballers` (
`footballerID` mediumint(15) NOT NULL default '0',
`fname` varchar(15) collate latin1_general_ci NOT NULL default '',
`sname` varchar(15) collate latin1_general_ci NOT NULL default '',
`value` decimal(15,1) NOT NULL default '0.0',
`PremTeamID` mediumint(15) NOT NULL default '0',
`position` varchar(15) collate latin1_general_ci NOT NULL default '',
`Importance` varchar(4) collate latin1_general_ci NOT NULL default '',
PRIMARY KEY (`footballerID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

The footballers table basically has a list of all the players in the premiership and the footballerscore table has a list of the player who played in a given week. For any one week I need to find out who DIDNT play. I can do this by comparing all the footballerIDs in both tables and the difference is the group I need. However I'm not sure how to put this into an SQL statement.

Comparing Tables
Let me set the scene for you. I have two tables on the same database:
hr_harassment (everybody who has already entered into a training class)
fields: lname, fname, class
hr_employee_list (everybody who needs to enter into a training class)
fields: Lname, Fname
I need to compare the two tables to figure out who has not yet signed up for the class. What would be the easiest way to do this? I am using PHP to program the page. I looked online and came up with this:

SELECT * FROM hr_employee_list AND NOT EXISTS (SELECT * FROM hr_harrassment AND hr_employee_list.Lname = hr_harrassment.lname AND hr_employee_list.Fname = hr_harrassment.fname)

But my browser tells me this:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in monitor.php on line 270

Comparing Two Sub_queries
I need to return the rows that are NOT duplicated. I am trying to be sure information on one db is the same on another db. I just need the odd rows returned. Is there an opposite of the union function?  

EX> Query 1 returns

acct_num product_id     count
1507692    100000500    1
1846486    106            3
1846486    100000500    1

Query 2 returns the same.

I want the row returned if they aren't the same.

 

Data Comparing
i'm writting a program that uses my sql to compare a date time feild to a date that i have to count call on one date the statment looks like this:

SELECT Count(*) FROM wab_answers WHERE wabScreen=1 And DateDiff(answerTime,'" & curDate & "')=0;

where curDate is string containing the date that i would like to compare. I'm not to sure on the correct way to do this. Just need a push in the right direction.

Comparing 2 Tables
I have a table of users which is updated once a week by the client sending me a spreadsheet, and me uploading the CSV to my scripts which then import the data into the user table. This all works fine. However instead of sending me incremental data that can be just imported, the client has now taken to sending me a complete data list. The problem with this is that I cannot just empty the user table and re-populate with the new data as I will lose the primary key values which I use elsewhere.
My solution to this was to create a new table for importing with the same structure as my user table, import the csv to there, then somehow compare the tables and add the rows missing from the import table into the user table.

Comparing Times
I'm creating a voting system, and want to prevent people from cheating. Therefore I'm logging their IP, and the time they voted, and what I'm planning to do is have a script which will delete any records which have been in the database for say 24 hours.

To get the length of time I was gonne use:

HOUR(TIMEDIFF(NOW(),time))

Comparing Dates
I have a releaselist. All data before today should be deleted. How do I do this?

DELETE * FROM releaselijst WHERE Release < CURDATE()

doesnt work

Comparing Two Tables
I have to compare two tables. They are both of more than 650.000 rows, and I have to find which ones are missing in one of them. I have tried to first find all the rows in table A, and then search through table B to see if you can find it there. But this takes way to long time. Too bad mysql4 does not take subqueries.
Does anyone out there have a good idea to get this done?

Comparing Two Tables
I was wondering if there was a SQL command I could use that would find similar values from two specific columns in two different tables.. possibly an intersect?

heres what I mean

Table 1
blogTitle="I love soccer"

Table 2
articleTitle="Soccer is fun"

Is there a SQL command that would be able to find the similarities between each column in each different table if, lets say, the user entered "soccer" as a query?

Comparing Differences
I want to find the fields that are in table A but not in table B.
If I have:

table A: id, name, scoreA
table B: id, name, scoreB


I want to find the scores that are in table A but not in B, by example:

table a: 1,john,12|2,mike,14|3,neal,17

table b: 1,hellen,14|2,nolhan,12|3,vicky,10

After make the query:

Score in A that are not in B: 17

Next And Prev DisplayOrder Values (was "Help With MySQL Query")
I have a table 'Album' containing columns 'PageID' and 'DisplayOrder' (both INT).
On each page that is displayed I want to have 'previous' and 'next' links to other pages, which are arranged via the DisplayOrder column.

At the moment I'm doing this in 2 separate queries:

SELECT DisplayOrder FROM Album WHERE PageID = $currentPage
$currentNo = [result of last query]
SELECT PageID FROM Album WHERE DisplayOrder IN ($currentNo-1, $currentNo+1)
Highly simplified but you get the idea. Would it be possible to combine this into one query?

Comparing A Datetime Column
I am trying to write a query that will delete all rows that are older than a specified date.

The problem is that I am fairly new to mysql and that I am not quite sure about how I should compare something in the format yyyy-mm-dd hh:mm:ss.

Would converting that date format using UNIX_TIMESTAMP(), subtracting that from the current unix timestamp and then comparing be a good way to approach this problem?

Or are there other functions that may be easier to use?

Also, on a curious note.. how portable are these built-in mysql functions to other SQL software packages?


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