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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Retreaving Data Based


I have tables called room_status and room_info

room_status= room_id : date : status

room_info= room_id : type : rate

What I want to do is only make an entry in room_status when
a room is booked, as it is obviously available otherwise(duh) but
I don't know how to format a SELECT statement to bring back
rooms available on a specific date by only returning results from
the room_information table which do not have an entry in the room_status
table for a specific date, which is the case if I don't formally record that
a room is available.




View Complete Forum Thread with Replies

Related Forum Messages:
Query Based On Data Of 3 Tables
this is what I've been trying to implement:

I have, say, three tables.

One is a user table, with id, username, etc
Second is a question table with Question ID, Question, Category etc
And third is an "answers" table that keeps answers given by the users. It has the classic id key, and Question id and User Id columns.

What I want to do is this:
Select a random question of category 1 lets say from the questions table for which user X has no record of answering in the answers table.

View Replies !
How To Get Data Based On The Month And Year??
"select month(str_to_date(fmonth,'%M')) from company where id=2;"
(Query 1)
The fmonth in company has values like 'March,October etc,...'

this would give result as 4 for april (fmonth values in company table).

i have another table which has values based on the date.(Transaction table)

i want to fetch the values from the transaction table based on the date which is greater than the month of selected value fetched by the first query and of the year of current year....

i tried the query ,

"select *from transaction where date_format(transdate,'%Y %m') >=
date_format(curdate(),'%Y %m');"
This query returned the data which has a transdate >= 2006-10

i know that i have to combine the two query,but couldn't get those things.


View Replies !
Schedule Data Extractions Based On Requirements
I'd like to SCHEDULE a task to run automatically once per week that would EXTRACT all records from PHPBB_USERS which have either been newly created that week or were edited by the client within the same period.

The data would extract to a COMMA-DELIMITED file which would then be automatically emailed using the PHP mail command to an intended recipient so that she can MERGE the datafeed into a larger and more complex offline database.

Not entirely sure how this would be done, but I'm sure CRON would somehow get involved with the task.

View Replies !
Update Column Data Based On Another Table
I've got 2 tables: 'city' that list over 2000000 rows and 'profile' where each row are associated to a city.

What I want to do is to update cities popularities based on profile without having to scan the hole 2000000 rows of 'city'.

So is it possible to make those 2 query in one so I do not need to do a php loop:

SELECT city, COUNT(city) FROM profile GROUP BY city;

then

UPDATE city SET popularity = COUNT(city) WHERE city.city_id = profile.city

View Replies !
Determining Which Table To Query Based On Data Within Tables
I have 2 tables:

default_categories
column 1: category_id
column 2: category_name
column 3: category_parent

custom_categories
column 1: custom_cat_id
column 2: custom_cat_name
column 3: custom_cat_parent

The custom_categories table won't necessarily have anything in it but if it does, I need to choose the data from the custom_categories table over the data from the default_categories table.

So if the default category has 3 rows with IDs | names:
123 | Dogs
456 | Cats
789 | Fish

And the custom category has 1 row with IDs | names:
456 | Very Cute Cats

I want my query of these 2 tables to produce the following IDs | names:
123 | Dogs
456 | Very Cute Cats
789 | Fish

I've tried joins like the one below but they aren't working because if there is no custom_cat_id, it won't give me the result for the default category_id.


MySQL
SELECT *
        FROM default_categories
        LEFT JOIN custom_categories ON category_id = custom_cat_id
        WHERE category_parent = ''
        AND custom_cat_parent = ''
        ORDER BY $order_by $sort




View Replies !
Query For Month Data Based On Occurance Against Master List
I have a query running nicely. Now I'm trying to expand it.

It pulls the data from a table based on matching the id with another table and part of the grouping is by month and 2 other criteria. Now I'm trying to get the data pulled by month to pull only the info where the id matches the master file AND the FRANID's pulled are the same for each month. I'm trying to get a comparisson across times, but not every month has all FRANID's, depending on when they were entered and I ony want data that exists with matches over set months, starting for now with 12, perhaps also for 6 and 3 next time.

I've simplified what I'm doing above, but it is detailed below.....

View Replies !
How Do I Replace Data In An Existing Table - Based On A Column With An Identifier
Each record in the table I want to update has a unique identifier: products_model. For a given model number, I want to replace its image, which is located in a field called products_image.

The file with the new data is a .txt file, a sample of which looks like this:

v_products_modelv_products_imageEOREOR
5361453614.jpgEOREOR
5361553615.jpgEOREOR
5372453724.jpgEOREOR

The beginning part of the table looks like this:
+----------------------------------+---------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------------------+---------------+------+-----+---------------------+----------------+
| products_id | int(11) | NO | PRI | NULL auto_increment |
| products_type | int(11) | NO | | 1 | |
| products_quantity | float | NO | | 0 | |
| products_model | varchar(32) | YES | MUL | NULL | |
| products_image | varchar(64) | YES | | NULL | |
| products_price | decimal(15,4) | NO | | 0.0000 | |
| products_virtual | tinyint(1) | NO | | 0 | |

From what I've read over the past few days...I think I need to:
(a) delete the EOREOR column from the text file;
(b) use the LOAD DATA INFILE command somehow, telling it to ignore the first line of column headers in the text file.

View Replies !
ORDER Based On One Field But LIMIT Based On Another?
Say I have a table with students and their grades, and I want to get the students with the top 10 grades, but the result to be sorted based on their name. How would I do that?

View Replies !
Selecting Data Form One Table That Is Based On An Entry In Another Table
This is the code I am using:

***********
SELECT co_name,city,country,logo_small FROM $info WHERE $info.co_name=$categories.co_name AND WHERE $categories.everyday_wear='y' ORDER BY co_name ASC
***********

I am using a while loop in php to loop through all of the records but no records are being displayed. What am I missing? Do I need to use a JOIN statement?

View Replies !
Select Data From 1 Table Based On Criteria From Another Table
is it possible to select all the data in one table based on a criteria from another table?

for instance i want to select all the therapist from massage_therapist WHERE massage_schedule.finish > 0.
i don't want merged results. i just need to list all therapist based on the where criteria from a different table.

these two tables have the therapist_id in common.

View Replies !
Select Based On FK
I have two questions regarding the MySQL v4.1.16 scenario below:

1. What should the FK on update and on delete parameters be (i.e., default, cascade, restrict, no action, etc.)?

2. How can I insert the correct id’s as implied below?

I have tried just about everything (including “Insert 
select”, “LAST_UPDATE_ID();”, etc.) and whenever I think I am starting to get close I either get more errors or ‘0 records added’ with no error message;

I would greatlyappreciate someone who could instruct me on how to accomplish this task.

View Replies !
Using A Web Based Database
My web site host allows me to create MySQL databases on its database server. I've created a database as a trial. Now I would want users of my website to supply data to the database and for me to be able to extract it for analysis.

View Replies !
Web-based Chat
I'm debating between 2 different table setups for a web-based chat system (gchat clone). The first is just one table labeled 'chat' which has the columns 'user_1' 'user_2' 'time' 'message'. The second would be dynamically creating/deleting tables with the user names as table names like 'user_1/user_2'. I don't know a whole lot about DB table organization but I was thinking the actual 'select' statement would be faster with seperate tables. Any ideas?

View Replies !
UPDATE Based On Value In Another Table
How do I update a table to remove orphaned references to a second table? I've deleted rows in the second table, which has a unique auto_increment key. The first table now has references to keys that no longer exist. I need to update the first table, setting the value to NULL where the referenced key no longer exists. Something like:

UPDATE table1 SET table2ID = NULL WHERE table1.table2ID NOT FOUND IN
table2.ID;

The NOT FOUND IN isn't SQL, of course, but I'm not sure what should go there.

View Replies !
Union Based Upon First Query
I have a query that I would like to use a union statement in to grab the number of replies to a specific thread. The initial topic thread is in a different table, which I am grabbing in the initial query... I would prefer to do this in the single query, however I supposed I could do a separate loops and grab the number of replies with a totally distinct query ....

View Replies !
Syntax Based On MS Access SQL
Our shop is using an old version of MySQL (3.23).In testing our database concept we put together a test database in Access and the sql statement in MS Access looks like

SELECT DISTINCT FROM table1.col1, table2,col1
FROM table1, table2
WHERE (((table1,col1) like "*" & table2!col2 & "*"));

this gives us output from both tables(tables1 and tables2) while looping over the values of table2.col2.How does MySQL do this type of function?

View Replies !
SELECT Based On 2 Tables
I'm writing some custom stuff to pull from a WordPress install I have one one of my servers.

For one function I want to SELECT all the rows from one table based on criteria from that table and another table (they are related by the row ID of the first table). Here is the SQL I have now....

sql Code:
Original
- sql Code

SELECT DISTINCT t2.* FROM wp_term_relationships AS t1, wp_posts AS t2 WHERE t1.term_taxonomy_id = '4' AND t2.post_status = 'publish' AND t2.post_type = 'post' ORDER BY t2.post_date DESC

SELECT DISTINCT t2.* FROM wp_term_relationships AS t1, wp_posts AS t2 WHERE t1.term_taxonomy_id = '4' AND t2.post_status = 'publish' AND t2.post_type = 'post' ORDER BY t2.post_date DESC

It seems to be returning too many results. It's just returning all the rows from wp_posts that match the post_type and post_status criteria and ignoring the term_taxonomy_id (from wp_term_relationships) requirement.

View Replies !
Items Based On The First Letter
we have products database with CD's, and would like to create an alphabetical list of artists, then display the CD's that the artist has underneath them.
The database has the products in them, with the artists name being called 'prod_artist_name'. the query i tried, though I knew it wouldn't work is:

SELECT *
FROM products
WHERE prod_artist_name LIKE '%n%'

Now, this displays all the artists with the letter 'n' in their name, obviously. just wondering if there was a way to display the artists with 'n' as the first letter of their name.

View Replies !
Rows Based On First Letter
I'm trying to figure out the fastest/best way to return rows based on the first letter of the title column in my table. For example, I want to get all the article titles that start with the letter "a".
Is there any difference between the two select statements? Any reason to use one over the other? Memory? Speed?

SELECT title FROM table WHERE LEFT(title, 1) ='a';
or
SELECT title FROM table WHERE title like 'a%';

View Replies !
Sql Vs Text-based Databases
currently my site is storing data in text files, using explode() and seems pretty fast to me. would mysql be faster? i have a second box where i could set it up.

View Replies !
Update One Col From Another Col Based On Primary Key
I have a table which stores referral URLs in column 'ref' and primary key of the table is 'clid' I have added another column which will store the name of the search engine referral by the name 'SearchEngine'. Now what I want to do is to avoid PHP processing and write a mysql query as follow,

Code:

UPDATE clicks
SET SearchEngine=(
SELECT (
CASE WHEN (LOCATE('.google.',ref)!=0) THEN 'Google'
WHEN (LOCATE('.yahoo.',ref)!=0) THEN 'Yahoo'
WHEN (LOCATE('.msn.',ref)!=0) THEN 'Microsoft'
WHEN (LOCATE('.microsoft.',ref)!=0) THEN 'Microsoft')
WHEN (LOCATE('.live.',ref)!=0) THEN 'Microsoft')
ELSE 'Others' END
),
@tmpo:=clid
FROM clicks WHERE ref!=''
)
WHERE (clid=@tmpo);

but it gives me following error,

Code:

ERROR 1064 (42000): 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 ') WHEN (LOCATE('.live.',ref)!=0) THEN 'Microsoft') ELSE 'Others' END),clid:=@tm' at line 1

Basically i want to parse referral url, decide the search engine name and then store its name in the new column based on primary key so that correct values are stored in correct record.

View Replies !
Date Based Calculations
I'm looking for a way to create a query that generates a record for every day of the last year and using that date information for each day generates a unique database query (sub query?)for each day of the year.
I could probably do this in php but I'd like to do it for performance reasons from mysql (or at least most of it).
Does any one know of any good online tutorial/s that may help me build this sort of project? Or have some basic scripts that may be a good starting point?

View Replies !
Update Based On Another Table
Is it possible to do an update in MYSQL based on another table? I have version 3.23 and when I try to run this statement:


UPDATE ApplicationTbl
INNER JOIN AcademicTbl
ON ApplicationTbl.CampusID = AcademicTbl.CampusID
AND ApplicationTbl.Application_Period = AcademicTbl.Application_Period
SET ApplicationTbl.App_Status = 'Qualified'
WHERE AcademicTbl.Sem_OnCampus >= '1'
AND AcademicTbl.GPA >= '2.4'
AND AcademicTbl.Judicial_Sanction IS NULL

It keeps saying its wrong. Even though I know its not

View Replies !
Update One Column Based On Another
I have two tables. One set up like this:

id item_id group_id userid outcome settled

The second is

userid yes no

I would like to look at the first table and find all rows that have a specific group_id, then update the userid yes/no based on the outcome on that row. Outcome Y then add 1 to the yes column of that userid, outcome N then add 1 to the no column of the userid. Is this possible in one SQL statement?

View Replies !
I Need To Be Able To Get A Result Based On 2 Different Queries
I have a query that dislpays a pick up route. It shows a list of clients that needs to be serviced on any given day. Than I have a different query that displays all the clients that have been serviced on that particular day.

Now I need to show the clients that did not get the service that day.

View Replies !
Sql Based Contact Form
how would I create a contact form that would store the results in a sql databse, be able to see the results in a text file, and also would have a link to delete that result from the database in the results text file?

View Replies !
Timestamp Based Queries
I would just like some links or advice to information on how to do a query based on a timestamp.

Ie, I would like to find all the records in a movie database where was made after the year 2002.

View Replies !
Increment Based On Another Column
I'm having a little trouble working out the best way of doing something.

I'm storing a key split across two fields, the first field is 3 letters, the second is three numbers:
CREATE TABLE table1 (
id_a CHAR(3) NOT NULL,
id_b SMALLINT(3) NOT NULL,
...
);
What I'd like to do is have it so that when a new row is entered 'id_b' is calculated as MAX(id_b) + 1 WHERE id_a = new_id_a.

Is it safe to do this as some sort of nested query or is there a better way?

View Replies !
User Based PHP W/MySql
If I were to take a few different (gpl released) php programs that use MySql databases for the user data, could I integrate all the users into one database?
For instance, a user signs up in one of my forums, and their info is stored in a database. Then if they go to my auction script using the same database, they don't have to sign up again.

My guess is that yes it would work, but I'd have to go through each php file and edit where it called for the table data in each database to point to the same places.

View Replies !
Web Based MySQL Editor
I am looking for a Web Based MySQL Editor to manage, database, users, etc and if you can, tell me why you like it, good points, bad points, etc. I use PHPMyAdmin right now, so I am looking for something possibly better.

View Replies !
Selecting Another Column Based On Max()
I've got a funky query I'm trying to set up. I've got this poll answers database, and each row has a qid that matches to a question. So I can group answers by the question they correspond to. Now I'm trying to select the total votes and the answer with the most votes for each question. The total votes part is working fine, but I'm having trouble with the winning answer part.

I've got a MAX(votes) that works well, and finds the answer with the most votes for every question, and returns its votes. What I want to do is select the `answer` column (the one that houses the actual text answer) of the answer with the greatest votes (the winner). Code:

View Replies !
SQL Selection Based On Date
I'm using this function / string to pull data based on yesterday:

$tomorrow = date('Y-m-d',strtotime('tomorrow'));

How can I pull data similarily based on "last month"?


View Replies !
Deleting Based On Subquery
i need to DELETE the results of this query :

SELECT bizName, COUNT( bizName ) AS name_count
FROM `datanewest` GROUP BY bizName
HAVING name_count >1
I use this to remove double entries. But when i run something lie this

DELETE FROM `datanewest` WHERE bizName IN (SELECT bizName, COUNT( bizName ) AS name_count
FROM `datanewest` GROUP BY bizName
HAVING name_count >1)
i get this error :

#1241 - Operand should contain 1 column(s)

View Replies !
Sql Statement Based On The Result Of Another?
I would like to use the result of one sql statement in another condition...

$select="select descr from ne_cats where " select sub_cat_id from ne_cats_rel, ne_cats where ne_cats_rel.cat_id='$cat_id'" "; .....

View Replies !
Ordering Based On Occurence?
I have this part of my query
SELECT DISTINCT country
FROM traffic_outgoing

and I want to limit it to the top 10 countries that have the highest number of occurences. How would I do that?

View Replies !
Selecting From One Table Based On Another?
I have a table for products

and another table for the type of product it is like this:

I need this is be in a seperate table because one product can be several different types like ring,band,wedding,three-stone,etc.

but how can I then select a product based on criteria from the types table

say I wanted to select all products that are type = "Band" and type != "Fancy" ?

View Replies !
Disk Based Cluster
I want to know mysql support disk based cluster. Because i want to migrate on mysql cluster 5.0 and i have 30 GB database. If i mysql disk based cluster supports that much space than that would be great.

Another question is that MyISAM storage engine in mysql supports table partioning ?

View Replies !
Select Based On Rarity?
I have a table and one column is titled "rarity." Every once in a while, ONE random row from this table will need to be selected... I want to select the random row based on the rarity column. All of the rarities would equal 1. For example, a rarity of .38 would have .38 probability of being selected from the table.

View Replies !
Getting Counts Based On Non-specified Date Ranges
I have a table which has, among other fields, a date field. I want to get a count of records where certain criteria are met for, say, three days in a row. For example:

NumWidgetsDate
11/1/2000
101/2/2000
201/3/2000
101/4/2000
151/5/2000
51/6/2000

I would like to know how many times 3 consecutive days have at least 10 widgets. In this case the answer is 1 because from 1/1/2000 to 1/3/2000 one day did not have at least 10 widgets, from 1/2/2000 to 1/4/2000 each day had at least 10 widgets, from 1/3/2000 to 1/5/2000, though all three days have at least 10 widgets, 1/3/2000 was already counted before so it should not count again, and from 1/4/2000 to 1/6/2000 one day did not have a least 10 widgets. Since 1/3/2000 was not counted before it would
otherwise qualify in the next set.

View Replies !
Creating A Query Based On Dates
I am trying to write a query (in PHP) which selects from a database all of the items which are in the future. My query is as follows

SELECT * FROM news WHERE ((news.date)>$today ORDER BY date

where news is my database, news.date is the the field which holds the date for the item and $today will be replaced my current date. At the moment it seems to display all values, which suggest its not functioning properly.

View Replies !
Change Value In Field Based On Order
I have a field that is an INT and can contain a value of 0 or greater. When the value is 0 it creates a unique situation and users of the site will sometimes change this to 0 on purpose because this value can have your item show up in the search results on the first page. Why, if a person orders the information ASC, it will show up first.

I have to allow this field to be 0, long story, but I want to "punish" them if this is so. Based on the type of search (ASC or DESC) as the user can pick. I want those items to always show up last.

Currently I am passing a variable that gets set via a form w/ that information, but I don't know how to check in the query how the variable is set. I was thinking CASE but I thought that only looks at a field in the db, not some variable that is being passed.

Either way, I hope this is making sense. Here is the query (pretty simple).

Code: ......

View Replies !
Enforce A Certain Constraint Based On Several Records
I'm trying to create a table "Works_In" as follows:

CREATE TABLE Works (
EID INTEGER NOT NULL,
DID INTEGER NOT NULL,
PctTime INTEGER NOT NULL,
PRIMARY KEY (EID, DID, PctTime),
FOREIGN KEY (EID) REFERENCES Employee (ID),
FOREIGN KEY (DID) REFERENCES Department (DID) );

The PctTime field shows the percentage of time that a given employee works in a given department (one employee can work in several departments).

My question is: how can I enforce that the PctTime value <= 100 ??

For example if the employee "John" works in Department "1" 20% of the time, and in Department "2" 80% of the time...how can I make sure that the total percentage is equal to 100%...

View Replies !
LIMIT Based On Unuiqe Values
i have a query where i search the table on the table using an alias (a in this case) and then find all rows for that user using the alias b, but now i need to limit the results to say 5 unique rows from table a but allowing any amount from table b, also table a may return multiple uids for one user

Code:

SELECT b.uid, b.field, b.value FROM user_s as a, user_s as b WHERE b.uid=a.uid <where clause for table a here> GROUP BY b.field, b.uid ORDER BY uid

View Replies !
SELECT Based On All Day Names And Their Hours
I have a table which has a DATETIME column which stores datatime for each record.

I wanted to calculate the total/average of the records for each day and then for each hour of that day ALL TIMES like not only the current week or current month or year but for all available records.

a sample output can be

Monday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

Tuesday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

...

Sunday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

I tried something like following

SELECT count(id) as cnt,HOUR(hitdate) as hr, hitdate FROM hits GROUP BY DAYOFWEEK(hitdate),HOUR(hitdate)

And I am getting the following results, (long result)

cnt hr hitdate
1274 0 2008-07-27 00:00:50
1235 1 2008-07-27 01:00:07
921 2 2008-07-27 02:02:13
830 3 2008-07-27 03:00:03
674 4 2008-07-27 04:02:49
617 5 2008-07-27 05:00:37
606 6 2008-07-27 06:01:41
545 7 2008-07-27 07:01:52
534 8 2008-07-27 08:05:58
630 9 2008-07-27 09:04:01
680 10 2008-07-27 10:04:41
688 11 2008-07-27 11:01:26
881 12 2008-07-27 12:00:22
745 13 2008-07-27 13:00:09....

View Replies !
Joining Tables Based On Condition
I want to have a field determine what table the field should be joint on. For example, I have a field that is one of eight different values (contacts, leads, accounts, ect...). I want to be able to join on the specific table specified by the field because this field determines what type the id field corresponds to.

View Replies !
Windows Based GUI To Manage Tables
What is best GUI to utilize to connect to my db to make edits to tables, etc...?

I thought MYSQL Administrator could do it but I can't connect to my database on a shared server... if this is to the right tool.

View Replies !
File Based Version Of MySql
I would like to create a program in C# and use MySql as a backend. Is there a file based version of MySql that does not require the server to be installed. I know that if I use a Ms Access db, I can manitpulate the data without the user having Access installed (using ADO). I want to know such a thing exists for MySql?

View Replies !
Calculating A % Based On Date Range
I have a table called TransResult and I have 2 data fields in it. I want to get the percentages for the 2 possiable values in TransResult and I want this done by date, so I can go backwards to compare what was done in the past months to what is done in current month.

This is what i have come up with so far, however my _total is giving me ALL records in the table not this months records, so my percentages are off, aside from the _total the values it is calculating are correct.

SELECT TransResult, COUNT(*) AS HowMany, (COUNT(*) / _total ) * 100 AS Percent FROM tbltranslog, (SELECT COUNT(*) AS _total FROM tbltranslog) AS myTotal WHERE MONTH(Date) = MONTH(NOW()) +0 GROUP BY transresult

View Replies !

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