Selecting Record From Multiple Computers
multiple client computers and 1 server computer - server holds a 'jobs' database with records that need to be processed
The client computer connects to server, and requests the next record. After it does the select statement to get the next record it does an update to mark that record as 'in progress' and no other client computer are supposed to take that record.
Before that can happen the second client also requests a job and gets the same one (the update has not happened yet or too slow and each client gets the same record) and each client is supposed to get a unique record.
Does anyone know if it's possible to prevent this? mysql table locking or row locking?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Selecting Record
iam trying to create a news page on my website that will display any of the news items as long as it is less than 10 days old, so i don't have to take them off manually. how do i write the query so that it looks at the current date and doesn't display any records that have a date more than 10 days before it. I have seen querys that find records between set dates but i want this to be ongoing if poss.
Selecting Record
I'm looking for the syntax that will find the record whose key is equal to, or as close as possible but smaller than, the value sought. Can it be done in a simple query, or do I have to use a MAX of all that are <= to get this job done
Selecting ONLY The LAST Record
I need to run a check when displaying a record, that tests to see if the current record is the last record in the table. I need a way to select only the last record in a table. Can you reverse the LIMIT feature somehow to do this?
Selecting 1 Record Per Foreign Key
I am trying to query a MySQL table and retrieve either the earliest or the latest message in each thread. The messages are in a table with MsgID being the primary key and fThreadID identifying to which thread the message belongs. Examples below. Any ideas on the SQL I need to use here? Code:
Selecting 1 Record Per Foreign Key
I am trying to query a MySQL table and retrieve either the earliest or the latest message in each thread. The messages are in a table with MsgID being the primary key and fThreadID identifying to which thread the message belongs. Example Table ============= MsgID (primary key) fThreadID ReceivedTimestamp (DateTime) 1 99 2004-01-02 11:10:15 2 99 2004-02-01 01:11:59 3 99 2004-05-17 18:15:01 4 102 2004-07-01 11:11:29 4 103 2004-07-01 11:11:11 Example Desired Result Set #1 (earliest msg from each thread) =============================== MsgID, fThreadID, ReceivedTimestamp 1 99 2004-01-02 11:10:15 4 103 2004-07-01 11:11:11 Example Desired Result Set #2 (most recent msg from each thread) ================================== MsgID fThreadID ReceivedTimestamp 3 99 2004-05-17 18:15:01 4 102 2004-07-01 11:11:29
Selecting A Single Record According To Date
I have this SQL statement; "SELECT * FROM event ORDER BY month ASC, date ASC"; But i'd only like to select the next one event in order of the date field. Instead of selecting them all. How can i order by the current date? The date and month are seperate fields.
Selecting First Occurance In A Given Period Of Record
I have a table to log sessions and user (connect_id) id's, start time etc - see below +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | connect_id | varchar(12) | | | | | | session_id | varchar(32) | | | | | | start_time | int(11) | | | 0 | | | client_ip | varchar(16) | | | | | +---------------+-------------+------+-----+---------+-------+ I need to create a report that will tell me, for instance, how many sessions were started today, that's easy I know but I also need another report that will tell me how many of those sessions were first-time visitors.
Copying Databases Between Computers
I was working on a database on my old desktop PC but it died on thursday evening, I`ve managed to get the .frm table files from the data folder from the desktop machine and copied them over to my laptop. I installed mysql onto the laptop and started the service. I then copied my old database folder into the data folder of the mysql install and tried to access it. MySql managed to realise the database was there and return the table names but it could not access the table whenever i asked it to describe it. As you would then suspect trying to run any queries also failed. the error code was continuously table:'databasename.tablename' doesnn`t exist Can anyone shed some light on this or will i need to restart my DB from scratch?
Running Mysql On Old Computers
I´m running mysql on a Pentium 166 Mhz with 16 Mb of RAM. Pretty old, right? I want to know if there is a way to improve performance. I don´t know, something about reducing the number of queries that it will respond or cutting out some features.
Set MySQL To Listen From Other Computers
I have a problem connecting to MySQL server! The server is working on the other computer than my scrpit(my web page). The IP of MYSQL computer is 10.0.0.2. and port 3306! When i try to connect like this : $link=mysql_connect("10.0.0.2.", "user", "password"); $db ="database_name"; ... I get the folowing massage: Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '10.0.0.2' (10061) in D:InetpubwwwROOT....... The ip, username, password and database name are all correct! It is said, that it's possible, that the MySQL is set to work on localhost! If this is the problem, where to configure mySQL, to be able to connect from other computer?
Connect From Windows Computers
I have MySQL 4.1.11 on a box with Fedora Core 4. On another computer (a laptop) there is Windows XP and I've installed SQLyog to connect to FC4 mysql server. As a test, I created a user called mytest with its host to % in the mysql server but when I try to connect from windows this error happens: Access denied for user 'mytest@192.168.0.5' using password NO. I've tried setting a password for this user using update.....PASSWORD('hello')... and using update.......OLD_PASSWORD('hello')... then flushing privileges and restarting mysql server (just in case) but the access denied error is still happening. am I configuring mysql server in a wrong way? or what should I consider or do to allow Windows computers to access the FC4 mysql server
Selecting Multiple
using SELECT with LIMIT with a query I can get a single row of a table to display but is there a way to get multiple rows non consecutive to display. For example i need rows 0, 85, 170, and 255 the multiples of 85 starting with 0. I am trying to make a new table from this data TABLE 1 -------------Table 2 A1 A2 A3 A4 B1 B2 B3 B4 ---> A1 A2 A3 A4 C1 C2 C3 C4 ---> C1 C2 C3 C4 D1 D2 D3 D4 ---> G1 G2 G3 G4 E1 E2 E3 E4 F1 F2 F3 F4 G1 G2 G3 G4 example using multiples of 3 The webpage is being created with php and database is MySQL4
1 Record To Multiple Records
I'm looking for an efficient way of doing the following... table1 - groupName, firstGuy, secondGuy, thirdGuy,... sample - 'Red', 2, 6, 3,..... table2 - guyId, firstName, lastName sample - 2, 'Jim', 'Smith' ; 3, 'Bill', 'Adams' ; 6, 'Tim', 'Jones' If I queried groupName = 'Red', how do I get the result to be the names from table2. Subqueries?result to contain: red, Jim Smith, Bill Adams, Tim Jones I hope this is clear.
Multiple Joins In Each Record
I'm a relatively inexperienced SQL newbie but need to do the following ... I have two mysql tables: tbl_clients which includes fields: mgr and sp the above two fields store the ids of emps e.g mgr 2 sp 3 and tbl_emps which includes fields: emp_id, emp_fname e.g 1 Fred 2 Sue 3 Bert I need to construct a SQL query that returns the names in place of the emp ids. e.g:
Selecting Across Multiple Tables
I currently have 3 tables that I want to select data from: categories, calendars, pages. Each table has a parent field (its parent category) and an order field (its order in the menu). What I want is a query that will search all 3 tables and return one ordered resultset of categories, calendars, and pages. I tried playing around with some queries, but couldn't really figure it out.
Selecting From Multiple Tables
I am a beginner when it comes to mysql and have really gone out of my own depth! I am sure it isnt too hard I just cant seem to figure it out! OK here is what I am trying to achieve. lets say I am on a page where the category_id of the current page is 2. I want to select product_id, product_model, product_image, product_price from the Products table where the product is in the same category as the current page, and the product must be featured. I have come up with this, but it brings back nothing. SELECT products.products_id, products.products_model, products.products_image, products.products_price FROM products, featured, products_to_categories WHERE products_to_categories.categories_id=2 and products.products_id=featured.featured_id Here is the structure of the tables I am using. featured featured_id products_id featured_date_added featured_last_modified expires_date date_status_change status products_to_categories products_id categories_id Products products_id products_quantity products_model products_image products_price products_date_added products_last_modified products_date_available products_weight products_status products_tax_class_id manufacturers_id products_ordered
Adodb - Selecting Multiple Ids Via IN ( ... )
i am new to using adodb, but it is quite a good solution... so, what i am used to do, if i have to select more rows by their id's i write "SELECT * FROM table1 WHERE id IN (1,2,3,4,5)" how can i do this via Execution in adodb (http://phplens.com/adodb/) ? if i pass array, adodb starts complaining, if i implode it, it adds quotes around the string... any help? $ado -> Execute("select * from table1 where id IN (?)", array(array(1,2,3,4,5)) ) //this does not work:(
Selecting From Multiple Rows??
i have made a voting script... every time someone votes it goes into a table called 'voting'... since people can vote on multiple things in the site there are multiple instances of each user in the 'voting' database... if each entry has a 'userID' a 'ratingGiven' and a 'objectBeingVotedOn' field how would i go about grabbing say the "ratingGiven" field from all of one particular user's entries .
Selecting From Multiple Tables
I am trying to select from three different tables. I can select from two of the tables, but once I add another table into the WHERE clause, there are no results. here is my query: SELECT k.keyword, k.keyword_id, l.label, uk.searchable, uk.displayable, uk.profile, uk.comment FROM keywords as k, user_keywords as uk, labels as l WHERE uk.user_id = $userid AND uk.keyword_id = $id AND k.keyword_id = $id AND l.label_id = uk.label_id"; What I am trying to do is get the name of the label (l.label) from the labels table where the label_id in the labels table is the same as the label_id that is in the user_keywords table. I have done this before successfully. This time, all of the other ids are provided (user id and keyword id), but we must distinguish what the label id is in the scope of the MySQL statement.
Selecting From Multiple Tables
I am running MySQL 4.1.20, but use a PHP front end mostly, so I'm not too familiar with the mysql command line options. I have a database with ~20 tables, which are data stamped. I'd like to do a select or delete statement that uses multiple tables. I know I can do select * from t1, t2, t3 where field= 'value' But since the table names change, is there a way to do some kind of wildcard expression for table names? Something like.. select * from t* where field= 'value'
Selecting Min,max,avg Of Multiple Columns
I have to select "min, max, avg, sum( if( somecolumn = 123, 1, 0 ) )" from 5 to 15 columns so far, each query is for different table. Is there any other way of doing that except writing all the columns to query ? Of course that job does the script, but still, query looks miles long. Example of table: CREATE TABLE `example` ( `ID` int(255) NOT NULL auto_increment, `some_int` int(255) NOT NULL default '0', `some_int2` int(4) NOT NULL default '0', `create_time` date NOT NULL default '0000-00-00', `some_int3` decimal(65,2) default NULL, `some_int4` int(255) NOT NULL, `some_int5` int(255) NOT NULL, `a_somecolumn` decimal(65,2) default NULL, `a_somecolumn2` decimal(65,2) default NULL, `a_somecolumn3` decimal(65,2) default NULL, `a_somecolumn4` decimal(65,2) default NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; So, I have to select these "min,max,avg,sum" from all the a_somecolumn.
Selecting From Multiple Tables
I want to have a better faster query to select rows from multiple tables and sorting them by date and time limit 20, currently im using the following query, but it takes LONG time and lots of resources and sometimes mysql crashes : Code: SELECT id, name, type, date, time from table1 Union select id, name, type, date, time from table2 union select id, name, type, date, time from table3 union select id, name, type, date, time from table4 union select id, name, type, date, time from table5 union select id, name, type, date, time from table6 union select id, name, type, date, time from table7 union select id, name, type, date, time from table8 union select id, name, type, date, time from table9 union select id, name, type, date, time from table10 union select id, name, type, date, time from table11 order by date DESC, time DESC LIMIT 0,20.
Querying Multiple Tables For One Record
This has been killing my coworker and I for most of the day now... perhaps someone else can help. We have five tables in a database... one field has the same name in each table, the rest of the fields are different. We need to query each table against the common field and when a match is found, retrieve all fields for that record in that particular table. I know you can do this with an IF-ELSEIF statement and query each table independently, stopping when the record is found. We would prefer to query each table at the same time and just grab the data--much shorter and efficient code, IMHO. Any ideas? We have tried several variations of JOINs, UNIONs, etc. to no avail.
Selecting Two Values From Multiple Tables
My apologies for making this post, i'm sure that this question has been answered before, but for the life of me I just don't know what keywords to use. Two tables, sold_items (buyer_id, seller_id) and users (id, nick). My objective is to loop through the sold items for a particular buyer_id, and retrieve the buyer and seller username (nick). The problem is that I don't get how I can select both nicknames when as far as I know, I can only join the buyer_id OR seller_id to the user table. This is how I would do it normally PHP $query = mysql_query("SELECT s.buyer_id, s.seller_id, u.nick FROM sold_items s, users u WHERE s.buyer_id = u.id"); while ($row = mysql_fetch_array($query)) { $buyer_nick = $row['nick']; $seller_nick = mysql_result(mysql_query("SELECT nick FROM users WHERE id = ".$row['seller_id']),0); } As you can see this creates a query inside the loop, but how could I select both nicks in a single query?
Selecting Totals For Multiple Dates
I have a form where a user can input two dates and I want to get a sum of the day's data for each of the days separately. So far the closest I've come is: // to display the total for one day SELECT sum( hplmnmoc ) FROM `inRtccCallType` WHERE host='wilsle03' AND date='2007-05-25' OR // to display the total for all days SELECT sum( hplmnmoc ) FROM `inRtccCallType` WHERE host='wilsle03' AND date BETWEEN '2007-05-24' AND '2007-05-31' With what I have so far I can either display one day's total or else a total for the whole period. Can anyone tell me how to get the totals for each day individually without having to perform multiple queries.
Selecting Data From Multiple Tables
I have three related tables. tv_observersation, which contains stationID with the start time and end time for a tv station program viewed (the stationID isn't a key field as the same station can be viewed different times). A stations table, which contains the stationID and the station_Name, and an advertisement table, which contains a list of advertiserID and which stationID they are subscribed too (a one to many table). I am trying to generate a query, that would take out info i.e, the info from only stations that a specific advertiser has subscribed to in the advertisment table, but I am getting duplicate info in the query results from the observations table for a specific table. I think it may be a problem with how I am using the select statement. Do I want to select from two tables observations, stations like I am below, or should I use the other two (stations, and advertisments) with the inner join statement. The objective is to retrieve only the stations that a advertiser is subscribed to from the observations table. Code:
Selecting Records Containing Multiple Values
I want to query a database for records with which the field 'network_letter' contains G,R,M, and Q and display those results back. Is there an easier way than doing the following: $query1 = mysql_query("SELECT * FROM global_pops WHERE network_letter='G'"); $query2 = mysql_query("SELECT * FROM global_pops WHERE network_letter='R'"); $query3 = mysql_query("SELECT * FROM global_pops WHERE network_letter='M'"); $query4 = mysql_query("SELECT * FROM global_pops WHERE network_letter='Q'"); and then merging those results into one variable and printing them?
Selecting Only The First Message From Each Of Multiple Users
I have a table of cellphone text messages from users. Columns include (among others) TimeStamp (DATETIME), MessageText (VARCHAR(140)), and PhoneNumber (CHAR(10)). I want to select only the first message received from each number in a given week. What query would I use to do this? I tried SELECT DISTINCT, but that seem to only apply to an entire row, not individual columns.
Is It Possible To Sum The Values Of Multiple Fields On A Single SQL Record?
I have fields for Goals and Assists. I want to take those 2 fields and sum them to make a 3rd field PTS, then send them to variable in my PHP code to be printed to the screen. My statement is this: SELECT player_stats.G, player_stats.A, SUM (player_stats.G + player_stats.A) PTS FROM player_stats WHERE player_stats.PID =10 AND player_stats.season =1 The statement breaks with the bolded part.
How To Insert And Update Multiple Values In One Record
How do I insert and update multiple values in one record. e.g. 1. How do I insert "dogs,cats, snakes" in one record 2. If I have "dogs, cats, snakes" in one record and I want to update it and add 'pigs' to make it "dogs, cats, snakes, pigs", how do I do that?
Selecting From Multiple Large Tables Quickly
My skills with MySQL typically end at "SELECT * FROM table WHERE stuff", so I've had a lot of trouble with optimizing this query. I've tried doing multiple select statements for this, but that usually comes out with an average execution time of 99s. This method has a execution time of 6s still, so I'd like to get it down. I have 4 important tables here (I'm only posting the columns which I use): `auth` UID mediumint(8) unsigned PRI NULL auto_increment username varchar(32) MUL clan_id mediumint(8) unsigned MUL 0 clan_abbrev varchar(7) MUL `clans` ID mediumint(8) unsigned PRI NULL auto_increment Abbrev varchar(7) MUL Name varchar(64) icon_id smallint(5) unsigned 0 `stats` UID int(10) unsigned PRI 0 kills mediumint(9) NULL `usernames` UID int(10) unsigned 0 ID int(10) unsigned PRI NULL auto_increment Name varchar(32) Uses mediumint(9) 0 `auth`, `stats`, and `usernames` are linked by `UID`. `clans` is linked to a row in `auth` based on it's `clan_id`. I need to search the `usernames` table for a `Name` which matches a certain text (I use "storm" in my example below). I need to return a result with matches to that search, with each row containing:The `UID` which links the tables together for that user.The matching `Name` from `usernames`The matching `username` from `auth`The `Uses` from `usernames`.The `clan_id` from `auth`.The `Abbrev` from `clans`.The `Name` from `clans`.The `icon_id` from `clans`.The `kills` from `stats`. The result should be ordered by `Uses` (from `usernames`) -- highest to lowest. The tricky part is that some users may have Ɔ' as their `clan_id` in the `auth` table, in which case the clan id, abbrev, name, and icon_id should all be blank (0 or '' based on the type). Here's what I managed to hammer out with my limited knowledge of SQL: ( SELECT usernames.UID AS `UID` , usernames.Name AS `result` , auth.username AS `playername` , usernames.Uses AS `Uses` , auth.clan_id AS `clan_id` , clans.Abbrev AS `clan_abbrev` , clans.Name AS `clan_name` , clans.icon_id AS `clan_icon` , stats.kills AS `kills` FROM `usernames` , `auth` , `clans` , `stats` WHERE usernames.Name LIKE '%storm%' AND auth.UID = usernames.UID AND clans.ID = auth.clan_id AND stats.UID = auth.UID ) UNION ( SELECT usernames.UID AS `UID` , usernames.Name AS `result` , auth.username AS `playername` , usernames.Uses AS `Uses` , 0 AS `clan_id` , '' AS `clan_abbrev` , '' AS `clan_name` , 0 AS `clan_icon` , stats.kills AS `kills` FROM `usernames` , `auth` , `stats` WHERE usernames.Name LIKE '%storm%' AND auth.UID = usernames.UID AND auth.clan_id =0 AND stats.UID = auth.UID ) ORDER BY `Uses` DESC It works great, but the average query takes around 6s (these tables have several thousand entries in each).
SELECTing Distinct Values Over Multiple Columns
I have a table setup for populating a drop down menu. CREATE TABLE catagory ( ID char(10) PRIMARY KEY NOT NULL, cat1 varchar(50), cat2 varchar(50), cat3 varchar(50) ); Now each row is for one client to populate so that he can be listed under multple catagorys. The problem comes in that I need DISTINCT catagories but say the client with ID 00000-0001 has a cat1 of greek, and a cat2 of pizza, where on the next, a client with a different ID has a cat1 of italian, but a cat2 of pizza. How would I word the query so that I can return distinct results from both rows AND columns or is this a problem on the PHP side of things (how i'm coding the page)? as it stands right now, my query of: SELECT DISTINCT cat1, cat2, cat3 FROM catagory; isn't working very well (I get all the results, as if the DISTINCT wasn't there)
Selecting Multiple Columns Including Encrypted Data
Is there a way of selecting all columns from a table, including (aes)encrypted columns without having to individually name each column name->value. e.g. SELECT * FROM table; instead of SELECT column1, column2, column3, AES_DECRYPT(column3, 'salt') FROM table; I only ask because I have tables with dozens of columns and specifying every individual column will be very time consuming.
Selecting Language Depended Fields Through Multiple Table References
For a long time i think i need your instructions dear people on sitepoint. I'm making a sql query for getting user info, but i dont know how to handle this situation: SELECT user.name, user.firstname, user.lastname, ___ as user.city, ___ as user.province FROM user, languagefield, city, province WHERE user.id = %i AND languagefield.language = %i AND city.id = user.city #tricky part AND city.name = languagefield.id AND city.province = province.id AND province.name = languagefield.id So i'm trying to get users first and last names plus city and province names from language tables. Is it possible with one query? How would you make SELECT and WHERE clauses? Im using this db tbl scheme: table : city id (int4) primary key name (int6) ref languagefield.id province (int4) ref province.id table : province id (int4) primary key name (int6) ref languagefield.id table : user id (int4) primary key firstname (varchar32) lastname (varchar32) city (int4) ref city.id table : language id (int3) primary key char2name (varchar2) name (int6) ref languagefield.id table : languagefield id (int6) language (int3) ref language.id value (varchar255) id + language unique ***** I'm also thinking and planning to set more current language depended content to my application, so this is very important part of my design, 'cause it could be reused when dealing with other tables and fields.
Selecting Multiple Columnn Values Into 1 Distinct/unique List
I have a table with several fields for email (primary email, alternative email, contact email) Some times, some of these fields will be blank and sometimes the same address will be enter for both primary and contact. I use this table and these fields to do a mailout but I don't want to mail people twice because there address occurs in more than 1 column. I need to end up with a list containing all email values from those 3 columns that is unique (no duplicates). I can do this by checking each one and putting it into a php array but thought there may be a nicer way to do it in the SQL?
Looking Up Duplicate Record Or Adding New Unique Record
CREATE TABLE tbllayer ( LayerID int(11) NOT NULL default '0', LayerSize int(11) NOT NULL default '0', IceTypeID int(11) NOT NULL default '0', Fingerprint char(16) binary default NULL, PRIMARY KEY (LayerID), UNIQUE KEY Fingerprint (Fingerprint), KEY IceTypeID (IceTypeID) ) TYPE=MyISAM; We have an internet monitoring application which stores objects in the above table, with the fingerprint an MD4 of the object. In general about 30% of the time an object monitored is already in the table, in which case we don't want to re-insert it, we just want to find out it's ID. The percentage may vary between 10% and 50% though. Currently we have a cache in our application which works like this: - object is monitored and its fingerprint taken - is the fingerprint in the cache? if so, take its ID from there - if not, do a SELECT on the table - if a match is found add it to the cache and use its ID - if not, INSERT the record into the tablem use its ID and possibly add it to the cache too Ok. In general, is it better to: - do a SELECT to see if the record exists and if not INSERT it or - do an INSERT, and if it fails then do a SELECT to locate the record What about if the duplicate ratio is high or low?
Automatically Record Date Of Record Entry
I have my database table set up and I have an HTML form that is PHP driven that will add the information entered into the form into to my database table. I have a local buy-sell-trade Website. The way it has worked is that people fill out a form and the results emailed to me. I then take the information and enter it into a Web page. I only want the ads to be displayed for 30 days. I keep the ad for a total of 6 weeks (displays for 30 days and sits in limbo for 2 weeks afterwords) and if not renewed within that 2 week limbo period - I delete it. Entering all the ads and keeping up with the dates manually has become a burden. I've only recently began looking into databases. My hosting company provides me with phpmyadmin and mysql 5.0. I'm new to all of this but I have managed to set up a database table and a HTML form that is PHP driven that allows ads to be automatically added to the database table. There is a lot I need to do to make this ideal, but one step at a time. First, I need to know the date (March 02, 2006) the ad was created or added to the database table. I know that I need to add some piece of code to my php form to record this information, but what code and where do I put it? I know I will need to create an extra field in my database table to house the date - I can handle this. I've read the date and time information here http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html but there's a lot there and I don't know which is right for my needs. Plus, it doesn't tell me how or where to insert it into my php form (or does it?).
Looking Up Duplicate Record Or Adding New Unique Record
CREATE TABLE tbllayer ( LayerID int(11) NOT NULL default '0', LayerSize int(11) NOT NULL default '0', IceTypeID int(11) NOT NULL default '0', Fingerprint char(16) binary default NULL, PRIMARY KEY (LayerID), UNIQUE KEY Fingerprint (Fingerprint), KEY IceTypeID (IceTypeID) ) TYPE=MyISAM; We have an internet monitoring application which stores objects in the above table, with the fingerprint an MD4 of the object. In general about 30% of the time an object monitored is already in the table, in which case we don't want to re-insert it, we just want to find out it's ID. The percentage may vary between 10% and 50% though. Currently we have a cache in our application which works like this: - object is monitored and its fingerprint taken - is the fingerprint in the cache? if so, take its ID from there - if not, do a SELECT on the table - if a match is found add it to the cache and use its ID - if not, INSERT the record into the tablem use its ID and possibly add it to the cache too Ok. In general, is it better to: - do a SELECT to see if the record exists and if not INSERT it or - do an INSERT, and if it fails then do a SELECT to locate the record What about if the duplicate ratio is high or low?
Getting Record Before Or After The Record That Meets The Criteria
In a query I want to get all the results and then order those results by last name, but then I want to filter those results down to only the record that comes before or after the record that has 'empno' = '1259'. I want to get all the results already ordered and then filter them down to one record either before or after (depending on what is needed) the record where 'empno' = '1259'.
Record Creates Record
I have a table that holds inventory information...primary key'd with an asset#. I have another table that I hold certain information in that I don't want in the main inventory table. I would like the second table to key itself and automatically enter a record when a device is entered. For example, I enter a scanner in my main table, but I want the DB to then also enter that assetNumber into the second table for me.
Select Statement With Multiple Counts/multiple Joins Trouble
SQL SELECT g.group_id, g.name, g.description, g.icon, g.user_id, g.date, u.username, count(c.comment_id) as comment_count, count(v.video_id) as video_count, count(m.user_id) as user_count FROM duo_groups as g LEFT JOIN duo_group_members as m on m.group_id=g.group_id LEFT JOIN duo_users as u on u.user_id=m.user_id LEFT JOIN duo_videos as v ON g.group_id=v.group_id LEFT JOIN duo_video_comments as c on v.video_id=c.video_id GROUP BY g.group_id, g.name, g.description, g.icon, g.user_id, g.date, u.username Will return My current problem with the above statement is with the counts. The count is accurate when only one of the counts is returned. However when more than 1 of the counts is returned the other counts (if they are not 0) will return the same number. For example look at the screenshot above. The first row, all three counts are the same but they are not accurate. They alll point to 8 because there are 8 comments, but there aren't 8 videos or 8 users. Same with the second row. There aren't 2 users only 2 videos.
Select / Insert Multiple Rows As A Single Row Of Multiple Columns
I have a nice database set up that contains information about orders and the items on those orders. If an order has 10 items on it, I can select the item data which returns 10 rows of data (let's say 5 colums each). Beautiful! Now I find myself needing to satisfy a program that requires all of the data on a single row. I can do this in a higher level language, but if I could accomplish it all in mysql it would be better. I don't need to sum or do any calculations. I just want to select those 5 columns of data about those 10 rows worth of items as a single row with 50 columns. For example, I'd want this: 1-1,1-2,1-3,1-4,1-5 2-1,2-2,2-3,2-4,2-5 To become: 1-1,1-2,1-3,1-4,1-5,2-1,2-2,2-3,2-4,2-5 The first complication is that the number of items on an order is variable, but is always at least 1 and can not exceed 20. The closest I've been able to get is to do something like: SELECT GROUP_CONCAT(item_number,",",qty,","",description,"",",price,",",location_number SEPARATOR ",") FROM items WHERE order_number=12345 This will give me a single text string containing the value content of the INSERT query (which will need to be manipuated outside of the SQL query to pad it with NULL values for the unused items' columns etc).
Connect/ Join Query Multiple Dbs Multiple Servers
Struggling to connect simultaneously to remotehost@my_ip_address AND localhost@my_field_db FROM my_field_tablet_pc to affect a custom sycnchronization that SQLyog will not allow. Both remotehost and localhost are built on WAMP stacks.
Joins With Multiple Tables And Multiple Rows
I'm making a good ol' forum, and i have three tables, users, threads and posts. when i query my threads table with a join, i need to access the users table twice to get the username of the first poster and last poster. But how? I can only figure out how to get one or the other. Is my design bad? eg SELECT TopicID, FirstPostID, LastPostID, Replies, Views, Topic, username FROM DiscussionThreads, users WHERE DiscussionThreads.FirstPostID=users.ID ORDER BY FirstPostDT DESC LIMIT 10 .
Multiple Languages, Multiple Products
I posted before and was helped immensely. I am designing a multilingual-capable site where each product may (or may not!) have a description in the user's chosen language. In this case, I want to get the default language description. Say my product descriptions table has fields prod_id, language, and description. When I have a single product and I want its description, I can retrieve it as follows:
|