I have a query to a database that returns a number X of results. I am looking to return a maximum of 10 results. Is there a way to do this without using LIMIT 0,9? I'll use LIMIT if I have to, but I'd rather use something else that will literally stop the searching, rather than look at all rows and then only return the top 10.
...
Suppose I have a datetime column.
"SELECT * FROM mytable WHERE thetime < INTERVAL 1 HOUR"
How do you write this in Django?
...
Hi,
I have two tables:
Contact (id,name)
Link (id, contact_id, source_id)
I have the following query which works that returns the contacts with the source_id of 8 in the Link table.
SELECT name FROM `Contact` LEFT JOIN Link ON Link.contact_id = Contact.id WHERE Link.source_id=8;
However I am a little stumped on how to return a list...
Why do people use SQLAlchemy instead of MySQLdb? What advantages does it offer?
...
When my code is stored and saved and out putted I keep getting these slashes \\\\\ in my output text. how can I get rid of these slashes?
Here is the PHP code.
if (isset($_POST['submitted'])) { // Handle the form.
require_once '../../htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config...
Hey guys I have a query and it works fine, but I want to add another table to the mix. The invite table I want to add has two fields: username and user_invite. Much like this site, I am using a point system to encourage diligent users. The current query which is displayed below adds the up votes and down votes based on the user in questi...
class LocationLog(models.Model):
user = models.ForeignKey(User)
utm = models.GeometryField(spatial_index=True)
This is my database model. I would like to insert a row.
I want to insert a circle at point -55, 333. With a radius of 10. How can I put this circle into the geometry field?
Of course, then I would want to check whic...
newthing = Link(user=request.user,last_updated=datetime.datetime.now())
However, this uses datetime , not the MYSQL "now()".
How can I use mysql's now()?
...
There are two tables. One is users info "users", one is comments info "comments".
I need to create new field "comments" in users table, that contains number of comments of that user. Table "comments" has "user" field with user's id of that comment.
What is optimal way to count number of comments by every user so far?
With php you shou...
Hi guys,
Quick question. I'm in a bit of a rush but if someone could quickly point me in the right direction I would be very very happy.
I have a field in the db, let's call it field_a which returns a string in the format "20,50,60,80" etc.
I wish to do a query which will search in this field to see if 20 exists.
Could I use MySQL MA...
How do I allow youtube videos on my web page using HTML Purifier http://htmlpurifier.org/.
Can someone help me on this on their demo I have to check Use experimental features. How do I fix my code to allow youtube videos?
...
Few basic doubts I have:
1. Is primary key column automatically indexed?
2. What should be criteria to select index column?
3. When should I club multiple columns?
4. Does MyISAM or InnoDB has any affect on which columns should be indexed? Probably not.
5. Are they really required, specially in case if primary key column is automati...
Basically I pull an Id from table1, use that id to find a site id in table2, then need to use the site ids in an array, implode, and query table3 for site names. I cannot implode the array correctly first I got an error, then used a while loop.
With the while loop the output simply says: Array
$mysqli = mysqli_connect("server", "login"...
I have 3 tables with values like below
**tbl_product**
recID pID price colour
1 BDPLA-0001 1.23 White
2 BDPLA-0002 2.23 Black
3 BDPLA-0003 2.28 Blue
tbl_product_size
recID pID size stock
1 1 2.0cm 10
2 1 ...
| time_before | datetime | YES | MUL | NULL | |
| time_after | datetime | YES | MUL | NULL | |
the_tag = Tag.objects.get(id=tag_id)
Log.objects.filter(blah).extra(where=['last_updated >'+the_tag.time_before, 'last_updated' < the_tag.time_after])
Ok. Basically, I have an object that's ca...
I am loading a bunch of rows into MySql in C#. In MS Sql I can feed a DataReader to SqlBulkCopy, but the MySqlBulkCopy only presents itself as a bootstrap for a bulk load from file.
So, my current solution is using a prepared command in a transacted loop.
Is there a faster way to accomplish bulk loading of MySql using a DataReader sour...
I am having a serious trouble using triggers in mysql.
Basically I am trying to update a row on after insert. I am using the existing value in the row and trying to update an other column of same row.
Ex:
Existing_Name Actual_Name
Product_Arc1 Arc1
Product_Arc2 Arc2
Product_Arc3
I am taking the value of Existing_Name and extracting...
Hi!
I'm using a nested set in a MySQL table to describe a hierarchy of categories, and an additional table describing products.
Category table;
id
name
left
right
Products table;
id
categoryId
name
How can I retrieve the full path, containing all parent categories, of a product? I.e.:
RootCategory > SubCategory 1 > SubCategory 2...
I have a heap based table in MySQL that I am trying to update via PHP, but for some reason, the updates do not seem to be taking place.
Here is my test code:
<?php
$freepoints[] = 1;
$freepoints[] = 2;
$freepoints[] = 3;
foreach ($freepoints as $entrypoint) {
$query = "update gates set lane='{$entrypoint}' where traffic > 50 limit 50";...
Am looking for a query to sum values in a particular time duration say an year or a particular month in an year using MySQL syntax. Note that my transaction_date column stores daily amount transacted.
Am example of a query that returns total sales in an year query would look something like this
SELECT SUM(transaction_amount) WHERE tran...