I am trying to write a query to select all records from users table where User_DateCreated (datetime field) is = 3 months from today.
Any ideas? Thanks!
This question was inspired by a previous question posted on SO, "Does the order of the WHERE clause make a differnece?". Would it improve a SELECT statement's performance if the the columns used in the WHERE section are placed at the begining of the SELECT statement?
example:
SELECT customer.id,
transaction.id,
transaction.efective_date,
transaction.a,
[...]
FROM customer, transaction
WHERE customer.id = transaction.id;
I do know that limiting the list of columns to only the needed ones in a SELECT statement improves performance as opposed to using SELECT * because the current list is smaller.
I've been reading a lot about the disadvantages of using "order by rand" so I don't need update on that.
I was thinking, since I only need a limited amount of rows retrieved from the db to be randomized, maybe I should do:
$r = $db->query("select * from table limit 500");
for($i;$i<500;$i++)
$arr[$i]=mysqli_fetch_assoc($r);
shuffle($arr);
(i know this only randomizes the 500 first rows, be it).
would that be faster than
$r = $db->("select * from table order by rand() limit 500");
let me just mention, say the db tables were packed with more than...10,000 rows.
why don't you do it yourself?!? - well, i have, but i'm looking for your experienced opinion.
thanks!
I am building a mail system. The inbox is only supposed to grab the last message (one with the highest time value) of a concatenation of user and sender, where the user or sender is the user ID.
Here is the table structure:
CREATE TABLE IF NOT EXISTS `mail` (
`user` int(11) NOT NULL,
`sender` int(11) NOT NULL,
`body` text NOT NULL,
`new` enum('0','1') NOT NULL default '1',
`time` int(11) NOT NULL,
KEY `user` (`user`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
So, with a table with the following data:
user sender new time
*****************************************
1 0 0 5
1 0 0 6
2 1 0 7
1 0 1 8
1 2 0 9
1 0 1 11
1 2 1 12
I want to select the following:
WHERE USER OR SENDER = X (in this case, 1)
user sender new time
*****************************************
2 1 0 7
1 2 0 9
1 0 1 11
How would I go about doing something like this?
at least i think that is what the problem is.
i am updating a mysql database through excel using an odbc like this:
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("datapath") = dpath
.Fields("analysistime") = atime
.Fields("reporttime") = rtime
.Fields("lastcalib") = lcalib
.Fields("analystname") = aname
.Fields("reportname") = rname
.Fields("batchstate") = "bstate"
.Fields("instrument") = "NA"
.Update ' stores the new record
End With
besides the fields above, i also have a primary key auto_increment field called rowid
for some reason the only field that gets updated is instrument. none of the other fields get updated..
however, when i try to do the same updating on a table that has no ROWID auto_increment field, it works perfectly
has anyone else experienced this kind of issue before?
Hello, I have a table with OWN_ID and OWN_Email -
3ace7cf80edd | [email protected]
3acf6af33ff7 | [email protected]
3acda2524e00 | [email protected]
3ad75583c9a7 | [email protected]
3ad74b018999 | [email protected]
etc.
the problem is that it should contain only a single ID per Email, also I need to replace all OWN_ID values in another table by highest OWN_ID value of the OWN_Email
i have a table with column:
Registereddate orgid
2010-06-05 10:16:00 1
2010-06-05 10:10:00 2
2010-06-04 22:31:00 3
... .
. .....
.
.
.
i need to get only last weeek dates and orgid from today to last 7 days date..
SELECT * from MainCategory where Month = 'May' and Day in ((cast(strftime('%d',date('now','-1 day')) as Integer)),(cast(strftime('%d',date('now')) as Integer)),(cast(strftime('%d',date('now','+1 day')) as Integer)));
Whenever I run this query in sqlite so it returns me 33 records instead of 3. I am insterested in fetching on 3 records of the current month but unable to do so, so plz assist.
--Please note: if you can't assist so plz don't post irrelevant answer.
I have also modified and try to make it simple but not achieve
Select day, month from MainCategory where Month = 'May' and day in ((date('now','-1 day')),(date('now')),(date('now','+1 day')))
i am connecting to a mysql database through excel using odbc
what does this line do?
Set rs = oConn.Execute("SELECT @@identity", , adCmdText)
i am having trouble updating the database:
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("datapath") = dpath
.Fields("analysistime") = atime
.Fields("reporttime") = rtime
.Fields("lastcalib") = lcalib
.Fields("analystname") = aname
.Fields("reportname") = rname
.Fields("batchstate") = "bstate"
.Fields("instrument") = "NA"
.Update ' stores the new record
End With
it is ONLY updating .Fields("instrument") = "NA", but for all other fields it is putting NULL values
I have many tables with identical schemas but different names. Can I create a single representative DBML/DataContext and re-use it for all the tables, or do I have to drag every table into the dbml designer?
I created a query in Microsoft Access like the one below:
SELECT Deliverables.ID, Deliverables.Title, Deliverables.Summary, Deliverables.Header_Code, Deliverables.Header_Code.Value, Deliverables.Sort_order, Deliverables.Pillar, Deliverables.Pillar.Value, Deliverables.Misc_ID
FROM Deliverables
WHERE (((Deliverables.Pillar.Value)="Link Building"));
But my problem is that this query locks my fields and I cannot make changes to the table using the query view.
Any suggestions? I am using Microsoft Access 2007
this is my code for uploading image in database but image are going to the desird forlder...but when i m tryin to retrieve the images to diaplay,,they are not displayed..anyone help me......
$category=$_POST['category'];
$uploadDir = 'D:/xampp/htdocs/js/wordpress/wp-content/plugins/img/imagess/ ';
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName,$filePath);
if (!$result)
{
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
global $wpdb;
//$insert=$wpdb->insert('images',array('image_name'=>$filePath,'cat_name'=>$category),array('%b','%s'));
$insert=$wpdb->insert('images',array('image_name'=>$filePath,'cat_name'=>$category));
$wpdb->insert('categories',array('cat_name'=>$category));
echo "Successfully Submitted";
table1 - id, time_stamp, value
This table consists of 10 id's. Each id would be having a value for each hour in a day.
So for 1 day, there would be 240 records in this table.
table2 - id
Table2 consists of a dynamically changing subset of id's present in table1.
At a particular instance, the intention is to get sum(value) from table1, considering id's only in table2,
grouping by each hour in that day, giving the summarized values a rank and repeating this each day.
the query is at this stage:
select time_stamp, sum(value),
rank() over (partition by trunc(time_stamp) order by sum(value) desc) rn
from table1
where exists (select t2.id from table2 t2 where id=t2.id)
and
time_stamp >= to_date('05/04/2010 00','dd/mm/yyyy hh24') and
time_stamp <= to_date('25/04/2010 23','dd/mm/yyyy hh24')
group by time_stamp
order by time_stamp asc
If the query is correct, can this be made more efficient, considering that, table1 will actually consist of thousand's of id's instead of 10 ?
EDIT: I am using sum(value) 2 times in the query, which I am not able to get a workaround such that the sum() is done only once. Pls help on this
I have a dropDownList on my form, where i need to have union of values from 2 colums of table [ost].
Type of this columns is currency.
I have russian version of access, default value of curency in "rur" and i need "uah".
I need to change format and save "order by".
I use this query:
(SELECT distinct FORMAT([Sum1] ,'# ##0.00" uah.";-# ##0.00" uah."') FROM ost)
Union
(SELECT distinct FORMAT([Sum2],'# ##0.00" uah.";-# ##0.00" uah."') FROM ost)
ORDER BY 1
Hello,
I am running into a wall regarding changing the password and was wondering if anyone had any ideas. Here are the database values prior to changing the password:
Clear Text password = abc1980
Encrypted Password = Yn1N5l+4AUqkOM3WYO7ww/sCN+o=
Salt = 82qVIhUIoblBRIRvFSZ1fw==
After I change my password to abc1973, salt remains the same, but the Encrypted Password changes which is supposed to happen:
Encrypted Password = rHtjLq3qxAl/7T1GfkxrsHzPsNk=
However, when I try to login with abc1973 as the password, it does not login. If I try abc1980, it logs me in. It is updating the database, is it caching the values somewhere?
Any ideas?
I would like to ask regarding this error...
Error 49 at line 5, column 6
bad bind variable 'S_ORD.payment_type'
Here is the code:
DECLARE
N NUMBER;
v_credit S_CUSTOMER.credit_rating%type;
BEGIN
IF :S_ORD.payment_type = 'CREDIT' THEN
SELECT credit_rating
INTO v_credit
FROM S_CUSTOMER
WHERE :S_ORD.customer_id = id;
IF v_credit NOT IN ('GOOD', 'EXCELLENT') THEN
:S_ORD.payment_type:= 'CASH';
n:=SHOW_ALERT('Payment_Type_Alert');
END IF;
END IF;
END;
I'm new to oracle forms so I'm not sure if I have a missing setup or anything.
S_ORD table exist and has a column payment_type, which consists of 'CREDIT' and 'CASH' value.
Thank you.
I've heard from some people that RoR doesn't marry cleanly with SQLServer. We have a series of historical, standardization to use SQLServer but if we can push back with valid reasons we can move to another db. One person on the team wants MySql and another wants Postgres, etc. I'm trying to stay out of the religious wars and really understand what the pain point is with SQLServer.
We're running the app server on a linux box, and the database will be on a windows box and the SQLServer that we're supposed to standardize on is 2008, if those details help any...
thanks in advance!
Is there some way to remove data about all users , roles e t c from some Web application into aspnet database tables ?
tables like dbo.aspnet_Applications (here is this application that I want to remove)
but also I need to remove all data with this application in other tables...
Hello everybody!
We have a web service which provides search over hotels. There is a problem with performance: a single request to the service takes around 5000 ms. Almost all of the time is spent in database by executing storing procedures. During the request our server (mssql2008) consumes ~90% of the processor time. When 2 requests are made in parallel the average time grows and is around 7000 ms. When number of request is increasing, the average time of response is increasing as well. We have 20-30 requests per minute.
Which kind of optimization is the best in this case having in mind that the goal is to provide stable response time for the service:
1) Try to decrease the stored procedures execution time
2) Try to find the way how to unload the server
It is interesting to hear from people who deal with booking sites. Thanks!
I've got a few tables in an access database:
ID | LocationName
1 | Location1
2 | Location2
ID | LocationID | Date | NumProductsDelivered
1 | 1 | 12/10 | 3
2 | 1 | 01/11 | 2
3 | 1 | 02/11 | 2
4 | 2 | 11/10 | 1
5 | 2 | 12/10 | 1
ID | LocationID | Date | NumEmployees | EmployeeType
1 | 1 | 12/10 | 10 | 1 (=Permanent)
2 | 1 | 12/10 | 3 | 2 (=Temporary)
3 | 1 | 12/10 | 1 | 3 (=Support)
4 | 2 | 10/10 | 1 | 1
5 | 2 | 11/10 | 2 | 1
6 | 2 | 11/10 | 1 | 2
7 | 2 | 11/10 | 1 | 3
8 | 2 | 12/10 | 2 | 1
9 | 2 | 12/10 | 1 | 3
What I want to do is pass in the LocationID as a parameter and get back something like the following table. So, if I pass in 2 as my LocationID, I should get:
Date | NumProductsDelivered | NumPermanentEmployees | NumSupportEmployees
10/10 | | 1 |
11/10 | 1 | 2 | 1
12/10 | 1 | 2 | 1
It seems like this should be a pretty simple query. I really don't even need the first table except as a way to fill in the combo box on the form from which the user chooses which location they want a report for. Unfortunately, everything I've done has resulted in me getting a lot more data than I should be getting. My confusion is in how to set up the join (presumably that's what I'm looking for here) given that I want both the date and locationID to be the same for each row in the result set.
Any help would be much appreciated.
Thanks.
Hi. At work, users are very happy to generate their own reports using Reporting Services' Report Builder.
But, alas, the queries it generates are very inefficient, and they don't use "WITH (NOLOCK)" - slowing down things for everyone.
These are reports that really do need to be run using latest data - can't be offloaded to the reporting server. And since they query very specific, detailed data, hypercubes are of no use here.
So the question is:
Is there a way to configure Report Builder's Data Models so the queries it generates always use "WITH (NOLOCK)" when querying a table?
My database has around 25 core numbers, in that weekly basis I need to create an index and drop index. While creating the index it takes long time to complete, my log file also keeps on increasing, and when I delete some numbers from that table also taking too much time (because weekly basis I have to delete 30 to 50 lack numbers and add 30 to 40 lack new number also).
Can u please give me the proper solution..
Hi every one , Wish u all a Happy New Year.
I am developing a website that uses facebook. Now for managing user i thought Using membrship provider. and choose'd to develop a Custom membership provider. Now my problem is that My data base schema dosn't match the Standred membership schema and the functions provided to Override take different argument than i expect. Like membership uses username as a username to log in. But i haev to use User email ID as the user name, also its searching functions is based on using Username as way to serach but i want it to search by UserID. Same Goes for User insertion, deletion, Updation..
please help me ....
Edit
Its just an idea, Would it be feasible to forcefully pass my values in the arguments and then handle them in my code.
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
when i m trying to execute sp then it through this error.
Could you please help it out.
I am using Oracle 9i and want to know to the definition(code) of predefined
functions in Oracle like,REVERSE(),REPLACE().
Is there any library of oracle where i can serach these library functions!
Please Suggest!!