Jump to content

lordvader

Members
  • Posts

    56
  • Joined

  • Last visited

    Never

Posts posted by lordvader

  1. Let's say my table has lots of columns, and every 5th column is an index.

    Then let's say I need results from severl indexes, and also from column #2 (which is not an index).

     

    Is it better to group all the indexes at teh front of my WHERE, or should I just go in order of the table's columns?

    To illustrate:

     

    WHERE index_column_1 = whatever

    AND index_column_5 = whatever

    AND index_column_10 = whatever

    AND column_2 = whatever

     

    versus:

     

    WHERE index_column_1 = whatever

    AND column_2 = whatever

    AND index_column_5 = whatever

    AND index_column_10 = whatever

     

    Thanks

  2. I'm exploring inner joins. This guy's wordpress plugin code has an inner join like this:

    FROM (((($wpdb->posts INNER JOIN $wpdb->term_relationships ON $wpdb->posts.ID = $wpdb->term_relationships.object_id)
    INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    INNER JOIN $wpdb->terms ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id))

     

    So I'm wondering if that's the same as:

    FROM $wpdb->posts
    INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    INNER JOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)

     

    thx

  3. Sometimes a blog post's comment will be too long. I want to enforce a maximum character limit, and if the comment exceeds this then it is presented with a slider so you can still read the whole comment, but the comment won't take up too much space. You know, like how your browser deals with long webpages.

     

    I don't think iframes are suitable here, so how could I do this? I don't need specifics, just the general concept and proper buzzwords. I can look it up myself.

    Thanks

     

    On re-reading this, I realize this is not necessarily a php question (although my site is written in php). Sorry about that.

  4. I want to add a column to an existing table, but first I have to check if the column exists. I can think of several ways to check:

    CASE WHEN EXISTS

    SHOW COLUMNS

    mysql_list_fields

    mysql_num_fields

    mysql_field_name

     

    But I was wondering in your experience, what is the simplest most efficient way to check if a column exists, if not, then add it to the table?

    thanks

  5. When learning creating tables, I see stuff like INT(11)... what's that paranthesis'd number do? I looked it up on mysql's site but I don't understand:

    Another extension is supported by MySQL for optionally specifying the display width of integer data types in parentheses following the base keyword for the type (for example, INT(4)). This optional display width is used to display integer values having a width less than the width specified for the column by left-padding them with spaces.

     

    The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters.

     

    That last sentence especially is what I don't understand. Could someone show some examples? Thanks

  6. Okay, I got a tinyint unsigned column, which means the highest number you could put in there is 255.

     

    Is there a 'mode' that would throw an error on the screen if your php tries to insert a value higher than 255?

     

    This thing that I'm writing has a counter which I don't want to able to run up indefinitely. It's not difficult to include the extra code to manually limit the count, but I don't want to if I don't have to, since there is already a built-in sort of limiter by using specific numeric types.

     

    I plan on giving my code to a lot of people for their sites, so it'll be too hard to find out what mysql mode everybody's host is set on.

     

    thanks

     

     

  7. Let's say:

    Primary Key | UID's | Additional Info 1 |  Additional Info 2

    1 | 5 | foo5 | bar5

    2 | 3 | foo3 | bar3

    3 | 4 | foo4 | bar4

     

    Primary Key is autoincrement

    UID is non-sequential, but unique numbers

     

    How do I sort this table so that UID is sequential again (lowest to highest) while keeping their associations with additional info 1,2, and keeping the primary keys where they are?

    1 | 3 | foo3 | bar3

    2 | 4 | foo4 | bar4

    3 | 5 | foo5 | bar5

     

    Thanks

  8. My primary key is unique id numbers, but because of the nature of my php scripts, they get inserted out of order. I assume that this slows down queries, since the engine has to search the entire db to find a specific primary key. But if it was autoincremented, it would know exactly where to look... Right?

     

    But my problem is that not every sequential number gets used... there's lots of gaps because the script will not re-use id numbers that belong to the data entries that get deleted before making it into the db.

     

    So if I have lets say, 10 entries in the db, # 1-10, and then I need to add a new row at the end of the table whose id is 15... will mysql with autoincrementing turned on, create rows #11-14? Or do I have to do it myself?

     

    If i have to do it myself, do I do a select on rows 11-14, to see if they exist yet? Or is there something more efficient?

    thanks

  9. Lets say I want to increment column "totals" in several different rows:

     

    UPDATE mytable SET totals=totals+1 WHERE id=1 OR id=3 OR id=7 OR (dozens more...)

     

    Is this the fastest syntax? Or is CASE WHEN THEN better? Or is there an even better way?

     

    Thanks

     

    By the way, I can't update every row's 'totals' column, only specific rows.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.