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




SELECT Search Query - Table Join Required? Help Please!! (PHP + MySQL)


I have a search form that has:
- drop down with states (nsw, vic etc)
- drop down with all business categories (retail, commercial etc)
- keyword / postcode field (2000, or 'builders')

The user gets results returned from the business table filtered by state (mandatory), which category is selected (mandatory) and by keyword (optional) or postcode (optional).

If keyword / search phrase is given then it will do search of the keywords fields of the business table (has already been indexed) in the selected category only. If postcode it will return all businesses in that category in order of distance from the given postcode.

I have 5 tables (additional fields ommitted):

'state'
state_id, name

'businesses'
business_id, keywords, name, postcode, state

'postcodes'
fromPostcode, toPostcode, distanceKMS

'categories'
category_id, name

'business2category'
business_id, category_id

Please dont thing i'm just pawning off my work here!!
Basically, i've got this working already, but only just, and in a very long and convulted format. Its far too long to post here, but since i'm not fully versed in table joins, i've been searching individual tables (e.g. SELECT *,MATCH AGAINST etc), building arrays, searching arrays again, and then building results at the end to fit into the paginator. Now the search is taking too long to perform, and i need a leaner alternative. not to mention theres way too many lines of code, and i just know theres a better way.

There must be a very simple way to achieve the following searches using table joins, can anybody please help me with 3 search examples below so i can try to understand joins better?

Search 1:
State + Category only

Search 2:
State + Category + Keyword

Search 2:
State + Category + Postcode

If there is no postcode, the others still need to display the data
filtered by distance from a default postcode of 2000.

I'd really appreciate if anybody has a few minutes free to help out here, and hopefully teach me something about effective table joins and searching. I've omitted the extra fields and tables from the real structure, and just left the relevant ones above - if theres anyhing missing or not making sense please let me know and i'll fix up asap.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Help Required In This Query....!!!!
I want to replace a character "/" with ⁄ in my database, is there any option to do that.

Its like : "this/is/a test line"
and after replacement it should looks like that : "this⁄is⁄a test line".

Query Required
Can anyone help me in building a query in which the table contains a field called name varchar and stdate date.Given this can anyone give me a query to get the total number of names of the present month.The month has to be taken automatically say using curdate().

Help Required Improving Query
the following query has been giving me problems. My users are reporting that credit is going down automatically and download counts seem to be overwritten with other downloads. I'm thinking using JOINS would be better, but I'm not sure which how best to structure it.

MySQL
UPDATE tb_members s, tb_userfield f,tb_downloads dl     SET     s.credit_available = credit_available - 1,     s.credit_used = s.credit_used + 1,     f.field24 = f.field24 - 1,     dl.info_downloads_web = dl.info_downloads_web + 1,     dl.info_downloads_today = dl.info_downloads_today + 1,     dl.info_downloads_30days = dl.info_downloads_30days + 1,     dl.info_last_download_time = NOW()    WHERE s.userid = '".$ses_userid."' AND f.userid = '".$ses_userid."' AND dl.key='".$download_key."'"

SELECT INNER JOIN Performance VS Single Table SELECT
I have designed my database using a somewhat oriented approach. Rows are objects, and different type of objects are in different tables, but since my objects share a common set of fields like ExpireDate, Archived, Draft, CreateDate, CreatorID, etc; I have an 'objects' table with these columns, and I have set up a foreign key in other tables where there is a need for a row-to-row integrity.

Now my question is, since I have to SELECT using INNER JOIN with object and the corresponding table, merely to filter out archived rows, I am wondering if I would be better off actually putting the common fields into each respective table and get rid of the 'objects' table altogether. I mean, is it more job for the server to actually JOIN the tables for each SELECT versus having a clean design with object oriented approach ?

How bad is my design, and what are the recommendations of experts who obviously were tempted to create an object oriented database design?

Select With Join Query Question
I'm trying to write a select query that involves 2 tables. One table
(Submissions) has a one to many relationship with the other table
(Jobs). I'm trying to find all the records in Jobs that do NOT have a
corresponding record in Submissions with a status of 1.

The problem I'm having is that when there is more than one record in
Submissions that match a record in Jobs and one Submissions record has a
status of 1 and one record doesn't, my query matches the one with status
!=3D 1 and returns the record for Jobs (even though it has a record in
Submissions with a status of 1 also).

I've tried a variety of queries including left outer joins and more
simple join relationships. I'm using MySQL 3.23.47 on Windows.

Here's an example query:

select j.job_id from jobs j left outer join submissions s on (j.job_id =
=3D
s.job_id) where s.status_id !=3D 1 group by j.job_id

Any help is greatly appreciated.

Query Search In Different Table Columns
I'm trying to set up an sql-query to find a value in the table, which can exist in different columns......

MySQL JOIN And Search
I am trying to make a query work and I am having troubles doing so. I would like to JOIN to databases by the zip code column in each and also have the query perform a search on text I entered in. I am putting the end result into PHP, but I am just having trouble with the code.

The below code works fine to bring back a general query with all records on it.

select consumer.email, zip.county FROM consumer, zip WHERE consumer.zip = zip.zip

How would I specify that I just want one zip code on the above query? I tried using LIKE 33764, but it does not work. Also, the code below is what I would like the above code to look like, the only difference is that the above would be joining 2 tables.

select * from state WHERE MATCH(county) AGAINST ('%$trimmed%' IN BOOLEAN MODE)
order by county

Select Data From 2 Tables (join) REGARDLESS Of One Table Not Containing A Row
SQL
SELECT o.title, o.quantity, o.price, o.product, i.supplierFROM store_order_inv o, store_inventory iWHERE o.product = i.productAND o.cart_order_id = ?-195509-3867'

my only problem is if a row with Product ID doesnt exist in inventory, no result is returned, EVEN if a row exists in order_inve table with that product.

So my question is, is it possible to select data from 2 tables, but where the presence of a row with matching PRODUCT field in the inventory table is OPTIONAL

SELECT With Three Joined Table Including A SELF JOIN
Here are my Tables

Tickets
-------
id

Notes
-----
NoTicket
epoch
note

What I want i select all the tickets, but showing only the most recent
note to that ticket.

I have tried:

SELECT t1.id,t2.epoch,t2.note FROM Tickets t1 LEFT JOIN Notes t2 ON
t1.id = t2.NoTicket INNER JOIN Notes t3 ON t2.NoTicket = t3.NoTicket
HAVING t2.epoch = MAX(t3.epoch);

But it always give me an empty set.

I'm using mysql Ver 12.22 Distrib 4.0.20, for pc-linux (i686)

I'm sure i'm close to it, but can't find out.

Table Join Query
I'm trying to join multiple database tables and having a little trouble with it, hope someone can help:
There are 3 tables with columns: id, user, date, time, action
I'm trying to get user, date, time and action from all 3 tables where the user equals "anyuser" and sort the result by date DESC, time DESC.

How To Join Three Table Into A Little Complicated Query
I am using version 4.1.22. I simplifying this for example's sake. I have three tables:

order:
order_id
tip_amount

item:
item_id
order_id
price
vendor_id

vendor:
vendor_id
vendor Name

Each order can have many items. Each item has one vendor.

I need a query that displays all orders grouped by order_id, EXCEPT where there are multiple vendors where I need it to show grouped by order_id in the first column then grouped by vendor_id in the second column. Plus I need the tip_amount to show ONLY on the first line of the order.

It would like this (notice order# 299 has two entries and the tip amount was added to the first record vendor record that order):

PHP

order_id    vendor_name    total    tip298          ABC             $30     $2299          DEF             $25     $4299          XYZ             $12     300          LKW             $17     $7...

Table Join Invalid Query
I have this table join below and I am getting an invalid query. How can I put the 15th line ($sql .= " group.id = master.id
"; and the 17th line ($sql .= " where ".$currentrow_sql ; together. Is it even possible to do that?

Adding Missing Rows In Table In 1 Select (+ Join) Command.
Hi all! Here's what I need to do :

I have two tables :
A B
a b c d
---- ----
1 z 1 k
2 x 5 l
3 c 6 j

I need a SELECT with JOIN that would give me :
A
a b
----
1 z
2 x
3 c
5 NULL
6 NULL

so I need to add the missing rows from the A.a and B.c JOIN,
how can I do that ?

I can't use a Union 'cause I can't use MySQL version 4.

MySQL Help Required In VBulletin
i run a forum....my problem is when my host was moving to another server some problem occured and my databased were showing some error as they were of 1KB ....

though thats not the prob..the main prob is i had the previous day's backup with me...and when i try to restore it ..it shows Database Error in the site...and database doesnt upload properly...please any MySQL guru help me cos without that i wud be losing 1000 posts

if possible add me on msn - ronak@holy-s hit.com

remove space between s & h

Necessary Files Required To Run Mysql DB
When installing the application into clients machine i want to install mysql 5.0 also.
But i don't want to install full mysql5.0 onto clients machine.Is it possible to copy some dll files and register it and able to connect to the MySql from java application.

MySQL Interface Required
I hope this question is appropriate for this group.

My server provides a MySQL database. Do I need a third-party interface to
add tables and records to it, or is their another way?

Different Syntax Required For Older Mysql?
I have a statement which works on one Mysql database but not another. The one which works is running version 4.1.18, the one that is not is running 4.0.24.

This is the query:

SELECT DISTINCT MONTH (col1), YEAR (col1)
FROM (SELECT * FROM test order by col1) SORTEDDATES_TAB

Is there a differnet syntax required for the different versions?

Mysql/phpmyadmin Installation Method Required
I just got anew laptop and I am currently trying to install all of my web applications. I can remember the last time i installed mysql and phpmyadmin it took me ages, som I was wondering if there is any wizard available that I could use to find a smooth way to install this.

MySQL Slow With 4GB Memory - Tuning Required?
I am using MySQL 4.1 on Linux (IBM Open Power Server). The Server has 4GB memory, 380GB hard drive.

I have a Java based application that runs in Tomcat in a Windows environment using SQL Server. As part of a customer project I have got the application to work on Tomcat on Linux with MySQL.

Both databases have a large amount of data in some of the tables, e.g. 500,000+ records in some of the tables. Some of the tables have indexes on them.

There is a specifc part of the application that is slow when running against MySQL (10 seconds to write a record to a table with 500,000+ records in it.) The same bit of functionality running against SQL Server is instance, e.g. 2 secomds max. The code is doing an insert statement. Once the insert has taken place we need to get the ID for the inserted record. This is using SELECT MAX....... The ID column is set as the Primary Key and is indexed. Code:

Multi-table Query In One Select - Possible?
Runnint Mysql 3.23.47

I have the following two tables:
backorder_notification
->product_code varchar
->email varchar
->date_added date
Products
->code varchar
->name varchar
->other stuff that is not important

Essencially - I want to get a count of the product codes that are in the
backorder_notification table ordered by count then by product name and
output the display:

Mysql Search Query
i would like to write a query to seach for the related information to display.

let say the user key in the word "sql", and in one of my keyword field i have data such as "mysql, database, java" and i want to call this row out, how can i do this?

MySQL Search Query
I have two tables as follows:

table 'question' with fields 'patient_id', 'answer_id' and 'terms', and

table 'answer' with fields 'answer_id' and 'answer_path'.

I need to search question.terms for a keyword match and then join that match to the corresponding foreign key (answer_id) in table answer to return 'answer_path'.

MYSQL SELECT Statement Depening On Search Results
I have a search form that contains 3 dropdown boxes:

- search_bedrooms
- search_price
- search_area

Each of these boxes contain values which will get info from a database when submitted, but they also have a value called [no preference], this is selected when the user doesn't want to search for any particular value.

When submitted it goes through to a page which has a MYSQL SELECT statement:

$query = "SELECT * FROM property_details WHERE area = '$search_area' AND price = '$search_price' AND bedrooms = '$search_bedrooms'";
What I need to know is if the user selects [no preference] on any one of the dropdowns, how can I make the above SELECT statement not include that in the search, but still search on the other criterias.

(e.g. if in the search_bedrooms dropdown I selected [no preference], how could it be excluded from the search, but still include area and price?)

I know it can be achieved with multiple SELECT statements,

[PHP, MySQL, FLASH] - Search Query
just a quick question what would be the best way to search a database, how should i query it? i have this so far:

<?
$name=$_GET['name'];
$company=$_GET['company'];
$address=$_GET['address'];
$phone=$_GET['phone'];
$email=$_GET['email'];
$web=$_GET['web'];

mysql_pconnect("host","random","random") or die ("didn't connect to mysql");
mysql_select_db("database") or die ("no database");

$query = "SELECT * FROM table_name WHERE Name, Company = '$name' AND '$company'";
$result = mysql_query( $query ) or die ("didn't query");

$num = mysql_num_rows( $result );
//echo ($num);
if ($num == 1){
while ($line=mysql_fetch_array($result)) {
$profile = "name_show=" . $line['Name'];
$profile = "company_show=" . $line['Company'];
//$profile = "address_show=" . $line['Address'];
//$profile = "phone_show=" . $line['Phone'];
//$profile = "email_show=" . $line['Email'];
//$profile = "web_show=" . $line['Web'];

}
print $profile;
} else {
print "error=Sorry, but I can't show results";
}
?>

it works but not very dynamically, when both companys are commented out in the while and query statements.

What i hope to have is a search where users can type in 1 letter and it will give them a result with all records having that letter in them and just by filling in one item in flash instead of all of them in order to begin the search.

MyISAM Vs InnoDB While Creating A Table Using Select Query
I have created a table using the select query.

****
for eg: create table table_name1 as select * from table_name2
****

now the created table is by default MyISAM format, what changes should i make to the query so that the created table is InnoDB.

Can I Use Select To Query Mulitple Data From Within A Field Of A Table?
I would be grateful if someone could tell me whether Select is appropriate to choose data within a field and separated by commas . I have made the foll. script. What I want to achieve, is below the script.....

Mysql Query Search And Find In String
I have following values in a field of mysql table. These values are stored as string [varchar] in the field.

Values : 3,4,10,21,20,8,100,2,6

How can I check through MYSQL query that 100 or 21 or 4 exists in the string?



Query (select/insert/update)Slows When Table Grows
I have a mysql database where tables are very simple. An example table will look like this:

create table myTable(
token varchar(255) not null primary key,
token_count int default 1,
frequency int
) type=INNODB;

A java program populates this table. The program reads from files (in batch mode) and inserts into myTable with following logic:

(1) See if the String to be inserted is present in myTable.(Uses SELECT)
(2) If not present the insert into myTable (uses INSERT)
(3) If yes update the table after adding the current frequency (USES UPDATE)

After processing each file issue COMMIT.

This goes on well for some time - but after the Table grows over 100,000 rows the process slows down considerably. The Strings I 'm handling is very large and I'm not sure how well Mysql behaves with very large String as primary Key.

My select and update statements are all based upon primary key(token in this case) - so question of setting index doesn't arise. Even then I have set index on token field - but it has degraded the performance. Also I have set the query_cache_size to 1MB even then it is not enhancing the performance.

A sample file has almost 30,00 to 50,000 lines. Each line having a string + blank + frequency.

After processing first few files - the Java program takes large time to process a single file - and subsequently the processing time increases exponentially.(as the tabel grows in size it slows down).

Help With Join Query Mysql 4.0
As I understand subqueries do not work in version 4.0

Here is what i am trying to do;

select a, b from table1 where table1.b != (select distinct c from table2);

Other words:
table1.b and table2.c have values I want to match on

I run
select a, b from table1;

subtract all out using

select distinct c from table2;

and leave me with a and b from table 1 that have no corresponding value of c in table 2

MySQL JOIN Query
I am a recreational MySQL user, and I tend to make some non-optimal queries. In my latest project I made some LEFT JOIN queries that were extremely slow.
I made two changes that made the queries almost instant.
1) indexed the columns that the joins were working on
2) optimized the tables being joined (using phpMyAdmin > Operations)

All I can say is WOW!!! I had no idea that the resulting difference in speed would be so great. After I did step (1) it added a tremendous amount of speed, and after I did step (2) the queries responed almost immediately. So if you are running slow with JOINS, give indexing and optimization a try.

Search Design: Keywords Table (MySQL)
I'm trying to implement keyword searching in my database.
Currently, I have a table containing all my entries with description and name.
The existing sql search utilises fulltext search to find the relevant data from the description and name fields. I'm thinking of adding an additional keyword table that would have higher relevancy in returning results (currently, you'll be lucky to find any relevant entries).
I have a separate table and the design is as follows:
REATE TABLE `keywords` (
`id` smallint(5) NOT NULL auto_increment,
`entryid` mediumint(9) NOT NULL,
`keyword` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
My other table that contains the description and name fields are `entries`

My problem now is, how can I match the search keywords with that of the table `entries` and `keywords`? I want to avoid using more than one sql query for each search.

For each entry in the table `entries`, there may be up to 20 keywords (e.g. 20 rows in `keywords` table). I'm open to another approach for the keyword table. The reason why I have a separate table is to facilitate management and hopefully be able to pool results in a way of a cloud for keyword statistics.
Can anyone offer any advice/help in this regard?



MySQL Query Assistance (JOIN)
This is probably easy for some of you DB gurus, but for me, I am having some trouble. Even after R(ing)TFM.

Background: This is for a home-grown photo gallery that I am making for my daughter, as she is going to study in Italy next year.

The query I CAN do is to pull all the sets of images from the DB and their associated images aka: `filename`

PHP

<?php
        
$query = "SELECT sets.sid AS `setID` , `name` , `filename`
        FROM `sets` , `pix_to_sets` , `pix`
        WHERE sets.sid = pix_to_sets.sid
        AND pix_to_sets.pid = pix.pid
        ORDER BY sets.time_stamp DESC";

?>


However, it would be "super cool" if I can limit this query to retrieve ALL the sets, but ONLY get one "filename" per set.

Any suggestions?

I am willing to read, so if you want to point me to a page in the manual that would help, I would appreciate it.

Or, if you are so kind as to show me the query, PLEASE explain it, so I can understand it, and do it myself next time.

Distinct And Join Query In MySQL
I have a query question, it may be really easy but somehow I cannot get it

What I have is a table with columns, two of which I will name Item1 and Item2,

I would like to get a distict set of pairs Item1-Item2 from this table, more specifically if table looks like this ....

Search Criteria In Join Clause (one To Many)
I've got a problem with a join clause. I have three tables: artikler, kategori and kategoriLink.

The table artikler has an unique field called artikelID

The table kategori has an unique field called kategoriID

The table kategoriLink has an unique field called kategoriLinkID and two other fields called artikelID and kategoriID

The following query returns 0 hits eventhough kategoriLink contains entries fulfilling both criterias in the select statement.

SELECT artikler.* FROM artikler INNER JOIN kategoriLink ON (kategoriLink.artikelID = artikler.artikelID) WHERE kategoriLink.kategoriID = 4 AND kategoriLink.kategoriID = 1

Does anyone have a solution to this?

Forming A Mysql Join Query (with Grouping).
Here goes it:

Lets say I have two tables, 1 named Genres and 1 named Movies.
Genres >>> genre_id, genre
Movies >>> movie_id, movie_name, genre_id, mpaa_rating

When doing a search on movies, I want users to be able to filter out the results by genre. To be more specific, I want all the genres to be listed (as a link) on the left side of the page, with their corresponding counts next to them.

Example:
Action/Adventure [15]
Comedy[7]
Documentary [3]
....etc, where the number is equal to the number of movies in the database that have a matching genre.

I've tried doing this...

MySQL PHP Table Join
I have 3 tables:

1. quiz [quizId, userId]
2. quiz_item[quizId, questionId]
3. question[questionId, question, answer]

A user creates a quiz and adds questions to quiz_item.I am unable to create a MySQL query that lists only the questions that are not in quiz_item for the particular user.

SELECT * FROM quiz_item RIGHT JOIN question ON question.intQuestionId = quiz_item.intQuestionId LEFT JOIN quiz ON quiz_item.intQuizId = quiz.intQuizId WHERE intUserId != '$intUserId'

This does not work!

MySQL PHP Table Join
I have 3 tables
1. quiz [quizId, userId]
2. quiz_item[quizId, questionId]
3. question[questionId, question, answer]

A user creates a quiz and adds questions to quiz_item.
I am unable to create a MySQL query that lists only the questions that are not in quiz_item for the particular user.

Mysql, Simple Table Join - How To Loop Through Records
I've been gradually learning and using PHP for about a year and I've now decided to start learning MySQL

I've got my first database up and running, and I can display records, edit/delete/search and sort records from that database. But I want to make things a bit more complicated and start making related tables.

I've decided to re-invent the wheel and make a very simple content management system for myself, just to see if I can.

I have a table called posts, which is what I enter my table content into, consisting of headline, creation date, post text and an id field.

I've also set up a table called comments which will allow users to add comments to my posts. In the comments table there's a field called id_post - which is the id of the post that the comment relates to in the posts table

I've already got my loop set up to loop through my posts records, but I'm confused about how I go through looping to get the comments records.

How do I do the loop?

I thought about doing an SQL query to the comments table nested inside my loop through my posts results

SELECT * FROM comments WHERE id_post='$id' ORDER BY stampcreate


But I assume this isn't the most efficient way of doing things....

Object Required: ''
I really don't know where this error is about

Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/includes/subnav/products_subnav.asp, line 3

My first few line of code are:

<%
    sqlHots = "SELECT ShortName, ProductID, ManuID, ProdTypeID FROM tblProducts WHERE New = '1'"
    Set rsHot = objConn.Execute(sqlHots)
%>
<div id="navlist">
    <table cellpadding="0" cellspacing="0" bgColor=#dbdbdb>
        <tr><td height=10></td></tr>
        <tr valign="top">
            <td vAlign=top align=left width=170>
                <font face="Arial, Helvetica, sans-serif"><b>Hardware</b></font>
                <ul>

And the line 3 is pointing to this line:
Set rsHot = objConn.Execute(sqlHots)

I looked all over and couldn't think of why.

Mysql Select Query Help
i am working with a shop script that i have inherited and i want to add the ability to have products in multiple categories.

To do this i have created an extra field in the product table called cat_id_2.

Now on the list products page I have the follwing call at the moment, which pulls all of the products for the current category...

$sql = "SELECT pd_id, pd_name, pd_price, pd_author, pd_thumbnail, pd_qty, c.cat_id, c.cat_description, c.cat_name
FROM tbl_product pd, tbl_category c
WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children AND pd_status=1
ORDER BY pd_name";
I tried to change this myself and added the extra paret to the WHERE clause and came up with this...

$sql = "SELECT pd_id, pd_name, pd_price, pd_author, pd_thumbnail, pd_qty, c.cat_id, c.cat_description, c.cat_name
FROM tbl_product pd, tbl_category c
WHERE (pd.cat_id = c.cat_id OR pd.cat_id_2 = c.cat_id ) AND pd.cat_id IN $children AND pd_status=1
ORDER BY pd_name";
But for some reason, instead of putting a product in two categories it puts the same product in the category twice, - its wierd.

Can anyone see anything wrong with what i have tried?


MYSQL Select Query
I am new to MYSQL.I am stuck with building a MYSQL Query.
I have two tables X and Y

Table x
column1
Id

Table Y
Column1 column2
ID Monday-Sunday

i need the ids which has saturday and sunday in the table Y.

Select Substring In Search
I have a table with a text-field that i do fulltext searches on. If I get a hit when I search I would like to retrive a short excerpt from the text where my searchwords where found. Can this be done in the same query or do I have to retive the whole text and fix it with php?

Search: Select Similar, Not Like
I want to make a search feature to the content of my website. I suppose, the classic way to do that is by making a form where the typed value $typed becomes a part of a select statement like this:

select from mytable where field like '%$typed%'

I would like to make a statement which allows for e.g. mis-spelling or different forms of a word. Say that the user searches for "woman" - and there happens to be content containing the word "women" instead ...

Is there perhaps also a way of ordering the results by similarity? E.g.:

select from mytable where field like '%$typed%' order by similarity

Makeing A Field Required
This is a very basic and simple question but very difficult to find an answer to. I have a table, and within that table there are 3 fields which i need to make required. I tried google for the past hour but it is so broad that it is aggrivating me. Somone please help, i'm getting so frustrated. How do I make it so that an existing field needs to be required?

Performance Advice Required
I'm after some performance advice if anyone has some. I've a table and query described below. The table holds about 13 million records. Query times for the query are about 135 seconds, which is way to long for live queries. Does anyone have any suggestions on how to reduce this. I realise live queries to a database this size might have to be tackled by spliting into other tables etc, but other sites manage this, and I just don't know how. I have already sumerised the data as much as possible to minimise the rows.

dns_stats CREATE TABLE `dns_stats` (
`hits` mediumint(11) unsigned default '0',
`domainname` varchar(100) NOT NULL default '',
`datetime` date NOT NULL default '0000-00-00',
`server` tinyint(4) unsigned NOT NULL default '1',
KEY `datetime` (`datetime`),
KEY `datetimedn` (`domainname`(20),`datetime`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

select domainname, sum(hits) as thits,server, datetime from dns_stats where domainname like '.moc.tsettsrif%' and datetime >= DATE_SUB(NOW(),INTERVAL 30 DAY) group by datetime,server order by datetime

and explain shows

1,SIMPLE,dns_stats,range,datetime,datetimedn,datetimedn,23,N,7925,Using where; Using temporary; Using filesort

This table gets updated each night, so is only read from during the day. The queries are almost exclusivly reads. I tried tests without the summary and grouping but this only takes about 10 seconds off, so I'm guessing almost all the time is spent retrieving the initial records.

Time Required By Database
Is there a way for me to print out the sum of all the time required by the mysql database? In most cases, I connect to the database once on a page view and then utilize multiple select, insert, etc. statements before disconnecting.

Before disconnecting, can I select the total time required by the database (and not perl) in that session? Even getting the time required by one select statement would be useful, too.

Required Fields Using PhpMyAdmin
I installed PhpMyAdmin and created a table.  When I insert a new record from a web page it lets me insert null values when in PhpMyAdmin null is set to NO.  How can I make these fields required?

Locking Required During Update
if a update query is executed with concurrent access to the database is table locking always recommended? i am thinking specifically about updates that do not take into account the value that is already stored in the DB.
let me give an example to explain. a person wants to update the salary of someone we could write:

Update table1 Set salary = "30" Where personid = 5;

in that case the user is not reading the salary value eg they are not doing salary = salary + 100 so is there a need to do any locking if multiple users do the same thing say using a thin client? i cant see the possibility of a lost update error occurring.

Password Required To Unzip Connector/J
I just installed MySQL on WinXP and immediately tried installing Connector/J. While the downloaded file is unzipping, the process stops and says File Callable Statement Regressio... is password protected. Please enter password in the box below. What passowrd do they want? Its not the password I just gave while installing MySQL. That one doesn't work.


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