Selecting Rows From The Past 24 Hours
I have some data rows, and they contain date entries in a datetime formatted field - e.g.:
2006-07-05 01:30:03
2006-07-05 01:46:36
2006-07-05 01:20:41
I would like to select rows from the table for the past 24 hours
It would be something like:
SELECT fldID, fldName, fldDate
FROM
my_table
WHERE
.... fldDate is within the last 24 hours
But I'm not sure how to do it.
I've used the date_format function before, but that might not help.
Then I found the date_add function - so if I did this:
SELECT DATE_ADD(��-01-02 23:59:59', INTERVAL -24 HOUR);
It would return:
1998-01-01 23:59:59
That looks good - but I'm not sure how I can build it into my statement to only return rows where the data_format field contains data less entered in the last 24 hours.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Most Products Flagged In The Past 24 Hours (was "Query Help")
I need a little help setting up the logic behind a query. Here is the situation: I have 2 tables. Product table. Flag table (flagID, productID, date_flagged). Users can flag products. *date_flagged is a INTEGER unix timestamp. I would like to be able to setup a query where I can pull up products that have been flagged the most in the past 24 hours. At first I figured I would COUNT() the flags and GROUP BY productID, but this of course will only give me the most flagged all time, and because of the grouping by productID will not allow me to filter it by date.
Selecting Past 12 Weeks Records
Im trying to grab the past 12 weeks records in a table. here is my code: $query1 = "SELECT * FROM table2 WHERE compdate > DATE_SUB(NOW(), INTERVAL 12 WEEK) ORDER BY compdate"; if($result1 = mysql_query($query1)) { $amount = 0; while($row = mysql_fetch_array($result1)) { $compdate = $row['compdate']; $compdate = substr($row['compdate'],8,2); $compdate = ltrim ($compdate, "0"); $days_array[$compdate] = 0; } } else { echo mysql_errno().": ".mysql_error()."<br>".$query1; } And here is the error: 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WEEK) ORDER BY compdate' at line 1 SELECT * FROM table2 WHERE compdate > DATE_SUB(NOW(), INTERVAL 12 WEEK) ORDER BY compdate
PHP - Can't Add Rows Past A Certain Id Number (127)
I've got a table which has about 70 rows in. The rows' ids start at 1, have a large gap in the middle, then range up to 127. If I try to add a new row with an autoindexed new id, I get the following MySQL error: duplicate entry '127' for key 1. If I add a new row with a lower id, e.g. 6, there are no issues - it works fine. If I delete row 127, or give it a lower number, I can then add a new row as normal, but then the error happens again for all subsequent rows. Everything was working fine with the page that adds new rows until it got to 127. Is this some kind of magic number I don't know about?
Rows In Past Month
I know I'm not writing this SQL command properly, please correct it for me. sql Code: Original - sql Code SELECT newsid,title,posted,content FROM `news` WHERE NOW() - `posted` < 2678400 SELECT newsid,title,posted,content FROM `news` WHERE NOW() - `posted` < 2678400
Selecting Records Younger Than 24 Hours Using SQL Query?
I have a TIMESTAMP(14)-field in my db and I need a quick way to select records younger than 24 hours, WITHOUT using PHP to convert around. I'm pretty sure this one should be quite easy, played around with something like: SELECT fields FROM db WHERE 'timestamp'>NOW()-INTERVAL 1 DAY) for hours right now (with DATE, EXTRACT, BETWEEN..AND etc.), and I either got error in my queries or bogus results.
Selecting Rows 10-20
Is there a way to select a certain group of 10 rows? Say, I want to have multiple pages for a huge result. I want 10 rows on each page. How would I go about getting rows 11-20 on page 2?
Selecting Rows
In my MySQL table posts, I have a field called tags. In this field, there are a bunch of words seperated by spaces (each one is a 'tag' for the posts). What I am trying to do is return all posts that have a certain tag, that tag being one of the words in the tags field. I know how to get all rows that have an exact value of something, like all posts by a certain author, but how do I get all the rows that contain a word in the long string of tags?
Selecting Rows
Hey guys, i've got a database with allot of rows. Each row has a timestamp field, wich indicated the time that that the row was added. The timestamp field is generated by time(). Now, my question, how can I get all the rows, for specific day? So I would like all the rows from yesterday, or 12 days back, or 3534 days back.
Selecting Rows
I have a database of addresses where I need to select out all those that fall under a particular road name, ie "Fake Street". I have the SELECT * FROM MYDATABASE WHERE part, but I am unclear on how to do the next stage. The column which holds the addresses is called "ADDRESS". In the ADDRESS column each row has the full address (1 Fake Street, 2 Fake Street etc). What statement can I use to select those rows which contain the street name?
Selecting Distinct Rows
I have a mysql query which I am trying to select distinct information with. Here is the query:
Selecting Rows Not In Array?
I'm trying to pull a single random field/row out of a mysql database, based on records that the user has not viewed already. I can either store an array of IDs in a session var or a cookie, but then how do I get mysql to exclude those IDs when selecting a random number? I'd like to 'SELECT ID FROM Table WHERE !in_array($array) ORDER BY RAND() LIMIT 1' but of course the "in_array" php code won't work in a mysql query. Is there a way to do this in mysql only, rather than having to iterate through the array and build a query with possibly hundreds of elements in the array: WHERE ID!=# AND ID!=# AND ID!=#,
Selecting Rows Having Repeated Value
Imagine we've got a MySQL table with the following structure: id int name varchar(255) The table contains the following data (id, name): 1 name1 2 name2 3 name3 4 name1 5 name2 6 name9 7 name1 Please help me with the query to select only those rows, in which "name" value occurs in this table more than once. So I would like to have the following result: 1 name1 2 name2 4 name1 5 name2 7 name1
Selecting Rows Not Within Another Table
I have 2 tables Stores and Store_Projects that im trying to pull all stores not in certian projects but belong to a customer. Heres the design of each CREATE TABLE `Stores` ( `storeID` int(10) unsigned NOT NULL auto_increment, `storeMetro` int(11) NOT NULL default '0', `storeManager` int(10) unsigned NOT NULL default '0', `storeState` int(10) unsigned NOT NULL default '0', `storeAddress` varchar(100) default NULL, `storeCity` varchar(50) default NULL, `storeZipcode` varchar(20) default NULL, `storePhone` varchar(20) default NULL, `projectStatus` varchar(20) default NULL, `storeSupervisorName` varchar(100) default NULL, `storeSupervisorPhone` varchar(20) default NULL, `storeSupervisorEmail` varchar(255) default NULL, `storeOtherContactName` varchar(100) default NULL, `storeOtherContactPhone` varchar(20) default NULL, `storeOtherContactEmail` varchar(255) default NULL, `storeNumber` varchar(50) default NULL, PRIMARY KEY (`storeID`), UNIQUE KEY `storeID` (`storeID`), KEY `storeMetro` (`storeMetro`) ) CREATE TABLE `Store_Projects` ( `projectID` int(6) unsigned zerofill NOT NULL default '000000', `storeID` int(11) NOT NULL default '0', `billRate` varchar(10) NOT NULL default '0.0', `associatePayRate` varchar(10) NOT NULL default '', `repsNeeded` smallint(6) default NULL, `storeServiceDateDay` smallint(2) unsigned default NULL, `storeServiceDateMonth` smallint(2) unsigned default NULL, `storeServiceDateYear` int(4) default NULL, `receivedPayment` enum('Y','N') NOT NULL default 'N', `invoiceNumber` varchar(25) default NULL, `invoiceDate` date default NULL, PRIMARY KEY (`projectID`,`storeID`) ) I had designed the query like this SELECT st.*, s.stateInitials, m.metroName, sta.stateInitials AS metroState FROM Stores AS st LEFT OUTER JOIN CustomerUsers AS cu ON cu.userID = st.storeManager INNER JOIN States AS s ON st.storeState = s.stateID INNER JOIN MetroAreas AS m ON st.storeMetro = m.metroID INNER JOIN States AS sta ON m.stateID = sta.stateID INNER JOIN Store_Projects AS sp ON sp.storeID = st.storeID WHERE st.customerID = 4 AND sp.projectID != 000002 But of course thats not going to work if the store is not in the Store_Projects table which it wouldnt be if its not in a specific project. So I need a way to pull all Stores with a specific customerID but is NOT in the Store_Projects with a specific projectID. Can anyone explain how this should be done within the query? I could do it by creating an array and then processing out all the stores but I would much rather let MySQL do the work for figuring this out.
Selecting Rows Not Within Another Table
I have 2 tables Stores and Store_Projects that im trying to pull all stores not in certian projects but belong to a customer. Heres the design of each CREATE TABLE `Stores` ( `storeID` int(10) unsigned NOT NULL auto_increment, `storeMetro` int(11) NOT NULL default '0', `storeManager` int(10) unsigned NOT NULL default '0', `storeState` int(10) unsigned NOT NULL default '0', `storeAddress` varchar(100) default NULL, `storeCity` varchar(50) default NULL, `storeZipcode` varchar(20) default NULL, `storePhone` varchar(20) default NULL, `projectStatus` varchar(20) default NULL, `storeSupervisorName` varchar(100) default NULL, `storeSupervisorPhone` varchar(20) default NULL, `storeSupervisorEmail` varchar(255) default NULL, `storeOtherContactName` varchar(100) default NULL, `storeOtherContactPhone` varchar(20) default NULL, `storeOtherContactEmail` varchar(255) default NULL, `storeNumber` varchar(50) default NULL, PRIMARY KEY (`storeID`), UNIQUE KEY `storeID` (`storeID`), KEY `storeMetro` (`storeMetro`) ) CREATE TABLE `Store_Projects` ( `projectID`.........................................
Selecting Recursive Rows
computers(id_computer,description,id_location); locations(id_location,description,father); I have this two tables: computers and locations; In locations I can insert a location and tell which one is his father, so I can have locations inside of locations. ------------------------------------------------ id_location, description, father ------------------------------------------------ 1, Main Building, 0 2, HRs, 1 3, Director, 2 4, Warehouse, 0 5, Office, 4 6, Director, 5 ------------------------------------------- When I insert a new computer, I tell in which location is that computer ------------------------------------------------------- id_computer, description, id_location ------------------------------------------------------- 1, Fujitsu-Siemens 4200, 2 2, Fujitsu-Siemens 5300, 3 3, Fujitsu-Siemens 4200, 5 4, Fujitsu-Siemens 5300, 6 ------------------------------------------------ Now I would like to select all computers from main building for example. I can not select * from computers where id_location=1 because that would not get the computers from HRs and Director. I would like to have all computers listed.
Only Selecting Specific Rows
Fields: studentID, reviewID, date I want to get all rows in a certain date range where there are at least 3 rows for a given studentID. In other words... Case 1: student has written 2 or fewer reviews during the date range. Don't retrieve these rows. Case 2: student has written 3 or more reviews during the date range. Retrieve ALL of their reviews during that time. So if they wrote 5 reviews, the query will have 5 rows for their studentID. Any ideas for this query? So far I got the date range to work using this. I'm struggling with the 3+ reviews part. SELECT `studentID`, `reviewID`, `date` FROM `review` WHERE `date` BETWEEN '2007-10-21' AND '2007-11-09' ORDER by studentID, `date` Any ideas?
Selecting From Multiple Rows??
i have made a voting script... every time someone votes it goes into a table called 'voting'... since people can vote on multiple things in the site there are multiple instances of each user in the 'voting' database... if each entry has a 'userID' a 'ratingGiven' and a 'objectBeingVotedOn' field how would i go about grabbing say the "ratingGiven" field from all of one particular user's entries .
Selecting Data In Rows
I am trying to select some data in a column but can't seem to figure it out. the table name is "Parameters" I want to be able to just select the "catch_addr" from the value column so all i get is the email address for the id of 33 mysql> select * from Parameters where id = 33; +----+---------------+--------------------------------------+ | id | parameter | value | +----+---------------+--------------------------------------+ | 33 | bounce_mess | This address no longer accepts mail. | | 33 | catch_addr | some@email.com | | 33 | nonexist_mail | catch | +----+---------------+--------------------------------------+ 3 rows in set (0.00 sec)
Selecting Rows In MySQL
I have a big database with about 500.000 rows. Each row consists of five columns with various information, e.g. a,1,1,1,1 a,2,2,2,2 a,3,3,3,3 b,1,1,1,1 c,1,1,1,1 I want to select all identical values from column 1 (e.g. the a in the above example). Then I want to copy the data in a new table, which is going to have as below: a, (1,1,1,1),(2,2,2,2), (3,3,3,3)...
Selecting All Rows From One Table That Is Not In The Other
What I want to do is this: select table1.id from table1,table2 where table1.id != table2.id .... I wish it was possible to write like that... but it doesn't I guess I can figure out the reason but anyway how should I do it? PLEAse help... example: table1 table2 id 1 id2 id 2 id 3 select table1.id from table1,table2 where <what to write here?> result: id 1 id 3
Selecting Unique Rows
I have a query that checks a list of users against a list of items and returns for example the following. SELECT users.username, ratings.recording_uid FROM users INNER JOIN ratings ON (users.uid = ratings.user_uid) WHERE ((users.username = 'a') OR (users.username = 'b')) which returns... username recording_uid a 1 b 1 a 2 b 2 b 3 a 4 b 4 b 5 How can I add to that query so that I know what user a has that user b doesn't and vice versa? eg. so that it returns username recording_uid a 3 b 5
Selecting A Certain Rows From A Database
if i wanted to select a certain range of rows from a database,is it possible?For example,i have a column in my database which is also a primary key and i wanted to select rows from where the primary key column is 21 - 40,would this sql statement be valid? SELECT * FROM tbl1 WHERE id=21 TO id=40;
Selecting Distint Rows
I have a load of images in a table, and these images are split into 2 different sections within my site. Some images may appear in both sections, but most only in one or the other. I want to be able to search the images table, and have the search results page show a list of thumbnails (this i have done already). If an image appears in both sections of the site, I do not want to show 2 thumbnails of the same image (this is what currently happens), instead I want to show a single thumbnail, and beneath it show that it is present in both sections. The common factor between these images that appear in both sections, is a field called image_code, which is unique to each actual image. If an image appears in both sections, it will have the same image_code. If I use DISTINCT I will only get a single image, but I am not able to show that it appears in the other section.
SELECTing Rows Where 1 Field Doesn't Repeat
Let's say I have a table something like this: id a b c 1 1 2 3 2 1 3 4 3 2 1 1 4 2 8 4 5 3 1 4 6 3 8 1 And then I want to select the rows, where "a" field doesn't repeat, so the 1st, 3rd and 5th. How do I do that?
Not Selecting Rows Where A Specified Field Is Empty
What I am trying to do in a query, is only select rows where a certain field is not empty. For example, I have a visitor logs table, with the following fields: id | date | pageVisited | referrer Now, I only want to select the rows where there is a referrer. Something like:
SQL Selecting Rows, Group By Increment
Lets assume the follow database: | ProductID | Cost | +-----------+------+ | 1 | 100 | | 2 | 10 | | 3 | 250 | | 4 | 900 | | 5 | 50 | | 6 | 60 | | 7 | 340 | | 8 | 100 | +-----------+------+ Is there an SQL function to group those values by a certain increment? For example a predefined increment of 100 would return: | COUNT | Cost | +-----------+---------+ | 5 | 0-100 | | 0 | 101-200 | | 1 | 201-300 | | 1 | 301-400 | | 0 | 401-500 | | 0 | 501-600 | | 0 | 601-700 | | 0 | 701-800 | | 1 | 801-900 | +-----------+---------+ Of course, I could loop through each increment with PHP and query each increment but that could get rather slow after a while.
Selecting Rows Where Foreign Key Is Null
I have this following query: SELECT l.NAAM, l.VOORNAAM, l.ADRES, l.LAND, l.POSTCODE, l.GEMEENTE, r.titel FROM westhoek.wtc_aansluitingen a, westhoek.wtc_leden l, westhoek.wtc_relatietitels r WHERE l.ID = a.lid AND l.RELATIETITEL = r.id AND a.jaar=2003 AND l.RELATIE Is Null ORDER BY l.NAAM, l.VOORNAAM but I also want to get the rows where l.relatietitel is null, so in Oracle SQL it would be ... and l.relatietitel = r.id (+).... but the (+) doesn't seem to work in mysql...
Selecting Rows From One Table With A Key That Doesn't Exist In Another.
I'm trying to select rows from one table that does not have a key in another table. For instance: I have a hospital table with two columns, id and name. I have a patients table with three columns, id, name, and locationid. Now I want to find those hospitals that have no patients. So I want to get those hospitals whos id does not equal any of the locationid's in the patients table.
Selecting Random Rows In A VERY Large Table?
I would like to select random rows in a very large mysql table but I don't want to use something like that: "SELECT * FROM tablename ORDER BY RAND() LIMIT 1000"; Because it's horribly slow when you have a large table like mine (6 million rows+).
Selecting Rows Whose Values Begin With A Certain Character
Let's say my table just contains just one column of words: apple bear banana water salt sugar cat zebra How would I write a select statement that selects all rows where the word begins with the letter b, s or z? SELECT word FROM mytable WHERE word (code goes here) Would I need a case statement for this?
Selecting Previous And Next Rows Based On One Input
let me start by what i am doing: SELECT msgid FROM messages WHERE uid=1; output: +----------------------------------+ | msgid | +----------------------------------+ | 1588ad275a80f22e6206364abbba530a | | 37ce77bea4481ab7ed2625055512467e | | 4bf7e4cb13590da24625821c795eb8d7 | | 57628792ba507161e3f73daff3c972b7 | | 91e95b3fbe9f04467023cfe84e6ed6e2 | | e710bb38be4f3cbd05b6db594f7e8805 | +----------------------------------+ how would i get it so if i enter a value it will return the previous and next rows. SOME_SQL WHERE msgid='57628792ba507161e3f73daff3c972b7' AND uid=1; output: +----------------------------------+ | msgid | +----------------------------------+ | 4bf7e4cb13590da24625821c795eb8d7 | | 57628792ba507161e3f73daff3c972b7 | | 91e95b3fbe9f04467023cfe84e6ed6e2 | +----------------------------------+
Selecting A MINIMUM And MAXIMUM Number Of Rows.
I have a problem where I want to get no more than 10 (LIMIT) of the newest records from a table that are within a month, but I want to get at MINIMUM 3 records, all using SQL. I can do : ------------------- SELECT * FROM updates WHERE date_of_update BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 1 MONTH ) AND CURDATE( ) ORDER BY date_of_update DESC LIMIT 0 , 10 ------------------- To limit it to the 10 updates no older than a month, but if there are no updates within a month I get nothing. So I would like to do something like : ------------------- SELECT * FROM updates WHERE ROWNUM() < 3 OR ((date_of_update BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 1 MONTH ) AND CURDATE( )) AND update_id IN ( SELECT * FROM updates ORDER BY date_of_update DESC LIMIT 0, 10 )) ------------------- This code will take the 10 most recent updates and then starts pulling them out as long as the number of rows is less less than 3 or the update is within the date range and one of the 10 recent updates. The problem is that mySQL appears not to have any kind of rownum function. Limit is a nice substitute except it only works for setting an upper bound, not a lower bound number of records.
Selecting Amount Of Rows With Distinct Values In Fields
how do i select the amount of rows in table that have a distinct field value. example: in my table i have a column (column a) that sometimes has duplicate values (sometimes 2 duplicates, sometimes more, sometimes no duplicates). how do i get the amount rows in the table that have a unique/distinct value in their column a (without the duplicates rows)?
PAST INSTALLATION
I know almost nothing about MYSQL. I can programme (more or less) in Paradox. I installed MYSQL 4.1 for Windows, but there is no explanation of how to get it to run like the databases I know. (Paradox/Access). All you get is a black-screen DOS-like dialogue box which is a command-line monitor. With Paradox/Access, you get a proper inferface to play with tables, and can either programme an application or not. MYSQL seems inpenetrable without special knowledge. If MYSQL has to be programmed by a programmer before you can even learn how to use it then it's not much use to me. Am I missing something?
Searching For Dates In The Past
I am relatively new to this. both the SQL Forum and SQL itself. I have searched through the FAQ's but am not sure if i'm looking in the right place. I need to know how to search for a date that is a set number of days in the past. eg. I need to find what the date was 61 days before 21/06/06.
Now() - 3 Hours
I was wondering if I can do this easily in mysql to change the time from server time to my time (server is in EST, im PST). PHP Code: $query = "INSERT into table(current_date) VALUES(NOW())"; PHP Code: $query = "INSERT into table(current_date) VALUES(NOW() - 3 hours)"; or should i just get the date and format it in php?
Run A Query Every X Num Of Hours
Is there a way of setting up a query that'll be run every hour or so? I'm running a site where I need a script executed every hour and every 24 hours.
Group By Last 24 Hours
I am looking for a query to produce a result set of the number of hits in the last 24 hours. I have a table called hits with the following fields (ip [bigint], created[timestamp]). What I want is a result set like this for the last 24 hours from now (assuming the current time is 23:15), hour hits ----- ------ 23:00 5 22:00 18 21:00 8 20:00 0 19:00 0 18:00 0 17:00 22 etc..... I tried the following query but it only gives me results where hits > 0. Ideally I want to keep the hours (for sequence) where the hits are 0. SELECT hour(created),count(ip) FROM hits GROUP BY 1
Now() Or Current_timestamp() And The Hours Value In Time
When I run select now(); or select current_timestamp(), I see the output like "2005-04-19 02:50:14". By reading the documentation I thought the the hour value should be in military format namely 14, but instead I see 02. How can I fix this problem? I have MySQL 4.1.10a database running on RH 9.0 server.
Create Index Takes More Than 5 Hours
I'm running MYSQL on a windows xp laptop with an intel centrino 1.60 GHz Processor and 512MB RAM. I've created a table and imported 27 million rows of data. I wanted to create an index on one char(55) field, as this field is a key against which many selects will be made. The information in the field is not conducive to having an integer key as any queries would require an extra join to the look-up (reference) table. Creating the index ran for more than 5 hours and finally gave up when there was no more space on the drive (creating the index apparently consumed more space (11GB) than the actual table (8GB). I'm wondering if this is normal time and space consumption for 27 million rows. Finally, doing an un-indexed query on this table : SELECT * from historical where reference = 'abcd'; Takes more than 1/2 hour. Is this also a normal amount of time? I understand that people are using MYSQL for data warehousing and major transactional applications.
Replication Master Crashed After 6 Hours
I recently setup replication, the master and slaves appears to work fine initially. After about 6 hours, the master mysqld process will start to consume 99% CPU and the load (avg. load per minute) will go to 3, 4, 6, 15, 24, 56, 312... in a matter of seconds! The master then stops responding and needs a reboot. This problem is reproducible, I have tested a few times. This is a screenshot of "top" command just before the master died: http://choonkeng.hopto.org/temp/replication-hang.gif There are plenty of memory and no disk swapping when the master goes 99%. Error and slow logs don't show any useful information.
Calculating 'office' Or 'working' Hours
How can I calculate elapsed 'office hours' between dates? e.g only counting time between 0900 and 1730 on weekdays, (and ideally excluding public holidays too, but that might be asking a bit much!)
Returning Clock Hours In Time Range
I have a table such as below: BreakIDStartTimeEndTime 108:00:0010:00:00 208:00:0010:30:00 308:00:0011:00:00 408:30:0011:00:00 What I need to find are the whole clock hours that are wholly within each time range. So, in this example: 108:00:00 109:00:00 208:00:00 209:00:00 308:00:00 309:00:00 310:00:00 409:00:00 410:00:00 Just to be clear, when I say clock hour I mean a 60 minute period that starts at one of the hours universally recognized for designating 1/24 segments of the day. E.g. 8:00 AM, not 8:01 or 8:30. I am sure there is some technical terminology for this, but it escapes me at the moment.
Find Days, Hours And Minutes Between 2 Dates
I have a datetime field in a mysql database and i want to output how many days, hours and minutes are left between the current date and the future date. So far i just convert the datettime to a timestamp like so: $start = strtotime($began); Where $began is the current time, basically i just need to know how to convert a timestamp to days, hours ect If i was to minus the current timestamp from the future timestamp.
Many-to-many Using Link Table And Selecting Only Rows That Have More Than One Link
Okay, I am not 100% sure if I am explaining this correctly, which is why I am having a hard time finding answers via a search. Here is my db structure: tbl_object ---------- object_pk name etc tbl_category ------------ category_pk name tbl_object_category_link ------------------------ object_fk category_fk I have successfully ran queries where I am looking for objects in just one category using: SELECT tbl_object.name FROM tbl_object, tbl_category WHERE object_pk=object_fk AND category_pk="2" However, if I want to only get objects that are in multiple categories, I am stuck. I can either pull ones that are in either/or like this: SELECT tbl_object.name FROM tbl_object, tbl_category WHERE object_pk=object_fk AND (category_pk="2" OR category_pk="1") The next "logical" step for me was to to this: SELECT tbl_object.name FROM tbl_object, tbl_category WHERE object_pk=object_fk AND category_pk="2" AND category_pk="1"
Nested Select Statement Taking Hours To Execute
I am running a sub select statment so I can compare a couple of tables. If I run the statement from two test tables of 1000 records in each, it will take nine seconds to get the results that I need. However, if I take the same statement and point it to the two tables which contain all the data I need to run against (50560 and 161680 records respectively), it takes hours to run...how long I'm not sure. I fired the statement off yesterday afternoon @ 3pm and it is currently 11:30am the following day...the select statement is still executing. Does anyone have performance on something like this?
|