Multiple Querys
I'm working on a query where I'd like to be able to search one OR two attributes. I've come accorss a few postings that lead me to the code below. It works fine if I put something in both attributes but fails if I leave the second blanc. Can you help?
SELECT * FROM books
WHERE title LIKE '%$title%'
AND title_sub LIKE '%$title_sub%'
ORDER_BY print_id
(p.s. I would lideally like to make the first attriubute optional. I may also want to add a few more attributes later)
View Complete Forum Thread with Replies
Related Forum Messages:
Multiple Querys Into One
How can I reduce multiple querys into 1 I have 1 main select PHP //get all the booking data from the tables, now I need to $cust_sql = mysql_query("SELECT DISTINCT customer.bid, customer.oid, customer.c_name, customer.pnumber, customer.mnumber, customer.party_names, customer.paid, booking.startdate, booking.enddate, booking.cid, booking.resort, booking.villa, booking.vtype, booking.adults, booking.children, booking.infno, booking.outfno, booking.atime, booking.cost FROM customer,booking WHERE customer.bid= '" . $_GET['id'] . "' AND booking.id='" . $_GET['id'] . "'"); if (!$cust_sql) { echo 'An error has occured with the db and is detailed below:<br> ' . mysql_error(); exit; } $row = mysql_fetch_row($cust_sql); I then run a another to return the country name using the booking.cid from the main result set. PHP $country_sql = mysql_query("SELECT DISTINCT country_name FROM country WHERE cid = '".$row[14]."'"); Is there a way to condense the 2 or more queries into the main one.
View Replies !
Two Querys In One
How can I make this both querys be only one recordset? select distinct grupo from sentient_campos where id_madre = 1 select distinct grupo_madre from sentien_campos where id_madre = 2
View Replies !
Merging Two Querys
I have two query that I I would like to be one, but I can't figure out how to do it. (mysql 3.23) $sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE login='%s' group by login",$usuario); $sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s' AND month='%s' group by login",$usuario,$getdate);
View Replies !
Dates In Querys
I'm returning the month from a datatime stamp in a mysql query using the following: MONTH(theDate) AS tMonth Only problem is, if the month is before november, it doesnt not return the preceeding 0, so for example.. september I only get 9 not 09. Is there any way in the query to define this?
View Replies !
Mysql Shuts Down During Rapid Execution Of Querys
I am using version 4.0.12-nt of MySQL and when I hit the enter key rapidly I can't connect to the database. The result is a message is returned to me from mysql that says I can't connect because the database is down. If I only hit the 'enter' key once (to execute the page that my queries are on(their are four queries on this particular web page)) my queries execute just fine. We have noticed that this only happens when we:
View Replies !
20 Different Tables Querys Slowing Page Display
I have an issue with a very large PHP page that calls over 20 different MySql Statements. This page is loading somewhat slow and i want to speed things up. I have looked into sql caching applications like http://eaccelerator.net/ and http://www.danga.com/memcached/ which i may install later, but i feel they are more for pages that are called frequently, my page calls the same data less times but can call more than 2000 different versions of the data. Being that my page is a little over 1000 lines, putting it all here is not gonna happen. I will try to shorten the code using examples... After writing the blow code.. it may be really confusing. I have stuck the file on my server http://www.empiresolutions.net/clien.../green_bar.zip in case anybody whats to get a better look. This file in it current state works fine, just is slow. Any and all help is so appreciated. Another Question... Can anyone provide suggestions on how to bench-test my sql scripts to see exact improvment speeds? Each indent means the following query is nested. Query 1 (2 Join Tables) Query 2 (2 Join Tables) Query 3 (1 Table) Query 4 (4 Join Tables, While Loop) Query 5 (2 Join Tables) Query 6 (1 Table) Query 7 (4 Join Tables, While Loop) Query 8 (2 Join Tables) Query 9 (1 Table) Query 10 (1 Table, While Loop) Query 11 (2 Join Tables, Calls every 10 rows from Query 10) Query 12 (2 Join Tables, Calls every 10 rows from Query 10, same as Query 11 basically) Query 13 (2 Table, While Loop) Query 14 (1 Table) Query 15 (2 Join Tables, This query and subs are called 4 times in a FOR loop) Query 16 (2 Join Tables) Query 17 (2 Join Tables) Query 18 (1 Table) Query 19 (2 Join Tables) Query 20 (1 Table)
View Replies !
Select Multiple Rows With Multiple Values In A Single Statement
when selecting multiple rows with different values in a certain row.. is this proper syntax? SELECT * WHERE name IN ('hello', 'cookie', 'smile', 'police', 'fun') It seems to work fine, but It came from another SQL version I believe .. not mySQL. Just wanted to double check, or see if there is a more correct way.
View Replies !
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).
View Replies !
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.
View Replies !
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 .
View Replies !
Select Multiple Keywords From Multiple Tables
am trying to do. I have a database called "members" that contains a table called "Reviews". This table has fields S1, S2, S3, S4, etc. that I want to search for the words ad, advertisement, and promotion. Here is the syntax I came up with that doesn't work: SELECT * FROM `REVIEWS` WHERE S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, XTRA='ad, advertisement, promotion' It would be perfectly fine, if easier, to search all fields in the table.
View Replies !
Multiple Update By Multiple Users
I'm looking at producing an application that will allow multiple users to order multiple items/ parts from what would effectively be an online store. These users could be ordering several hundred items/ parts at a time, each item/ part ordered representing one box or several hundred. Each part record will require the "total stock" to be down dated and each unit will require updated to show it as having been picked (plus other info). I'm looking at programming this in php 4.3 or php 5 using a current version of mysql. Looking around etc. I believe there are various options options open to me : 1 Create a pick list in a database table and have a "pick" routine pick the stock. This would ensure that the actual pick could only be carried out by a single process and the result of the pick request could be emailed to the user. This approach would provide the user with a very fast, responsive acceptance of an order request (but not real time - albeit almost). 2 Use Table Locks - This I understand may be the fastest but potentially could leave users with apparently hung screens, eg. if three picks were issued each taking 10 secs, then pick 3 would not start until the first two picks completed (20 secs). 3 Record Locks - I'm concerned that doing this would increase the time taken to pick the stock. But if the times were not excessive this would provide the user with an immediate "real time" response.
View Replies !
Multiple Batabases Vs. Multiple Tables
I am about migrate from an old program database to MySql (Running under RH LINUX)and I'm wondering which is the best option to do : I currently have one file for each of my modules, (I'm using filepro plus) , so like CUSTOMER, WARRANTY, ZIPCODES, INV, etc... like 2,000 files each with their own fields. 1) Should I create multiple databases on MySQL 2) Should I create a single database on MySql and with multiple tables ? Which one of these options is the best and more safer ?
View Replies !
Multiple Databases Or Multiple Tables
I have an application that is supposed to make multiple connections [around 10 connections per second] to a mysql database. The connections are done by mutlitple users at potentially the same time. I have to decide if I should use : 1)one database with one table for all users. 2)one database for each user. 3)one database with one table for each user. I would really appreciate if you can tell me what choice is best and why.
View Replies !
Multiple Books & Multiple Classes
The field names are as follows: bookList: "bookID", "title", "edition", "author", "ISBN", "newPrice", "usedPrice" classList: "CRN", "className", "professor", "courseNum" linkList: "CRN", "bookID" The goal is to run one query inputting the CRN and have it return all of the fields in bookList and classList. LinkList is only there to join the 2 since some classes have multiple books and some books are used for multiple classes. The erroneous query I was trying to use was as follows. SELECT * FROM (classList INNER JOIN linkList ON classlist.CRN = linkList.CRN) INNER JOIN bookList ON linkList.bookID = bookList.bookID WHERE CRN = 1 This query was the original. It worked but did not provide me any class information only the CRN of the class. SELECT * FROM linkList INNER JOIN bookList ON linkList.bookID = bookList.bookID WHERE CRN = 1
View Replies !
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:
View Replies !
Multiple Value
i know how to do a query with a single value... SELECT * FROM `category` where quiz_id = 32707 but how do i select records from several different 'quiz_id' values? i.e. 32707, 34501, 23450 i tried... SELECT * FROM `category` where quiz_id = 32707, 34501, 23450 SELECT * FROM `category` where quiz_id = 32707 or 34501 or 23450
View Replies !
WHERE With Multiple IDs
i am using JDBC. I want to get a ResultSet of all rows that have any of 10 different IDs in a certain field named 'IDN'. I tried this: 'select * from testTable where IDN = 'ID_1','ID_2','ID_3',....'ID_10'; ' this gave me an error. How can i pull off this query.
View Replies !
Use Multiple Between
I am trying to use a between statement to select multiple ranges from a database so for instance cabon_km could be between 0 and 120 or 151 and 180 SELECT * FROM elvdata WHERE carbon_km BETWEEN '0 and 120 OR 121 and 150' AND cost BETWEEN '0 and 6000 OR 6001 and 8000' AND engine_size BETWEEN '1000 AND 1200' OR '1201 AND 1400' AND fuel_source='Petrol' AND seats='5'
View Replies !
Multiple Or Or And
I am having some difficulty working on a query for a website that needs to pull information from several criteria. eg by default i need it to pull all the info and evaluate other expressions only if the variable is not null. for eg. select * from table where (length('var1') > 0 and (id = var1)) or (length('var2') > 0 and (size = var2)) or (length('var3') > 0 and (music = var3)) and id is not null. for some reason this just does not work.. It always returns all the records. I should note the value of the variables are numbers and not txt. i am not sure if that has something to do with it..
View Replies !
Multiple WHERE
I have a query: $sql = "SELECT * FROM notes WHERE uid='$_SESSION[uid]', class='$_GET[class]' ORDER BY time ASC LIMIT 10"; I want to get everything where the uid is equal to the session variable and the class is equal to the class var in the url... I have no idea whats wrong.
View Replies !
Multiple Count()s
I have a table with links, a log table to record clicks, and a vote table to record votes on the links. Is it possible to get the link data, the click count, vote count and vote total in one query? I can get the click count OK, but as soon as I add the vote count to the query, it multiplies them; e.g. for a link with 14 clicks and 2 votes, it tells me 28 for both figures. Here's the query: select lnk.LinkID, URL, LinkTitle, Description, count(log.LinkID) Clicks, count(Rated) Votes from fn_links lnk left join fn_log log using (LinkID) left join fn_rate vot using (LinkID) where CatID = $CatID and Status = $Active group by lnk.LinkID order by Created Then of course I want to include sum(Rating). I tried grouping on different things, but it makes no difference.
View Replies !
How-to Multiple Select
I'm studying a blog program. Given two tables : post and comment, i would like to retreve the number of comments for each post. In postgres the following is doable : select id, title, body, (select count(*) from comment where post_id = post.id) as total_comment from post How-to do the same thing with MySQL?
View Replies !
STD Of Multiple Columns
I want to calculate the standard deviation of data that are in multiple columns. I know how to calculate the STD of 1 column (e.g. X1 of table_X) using: SELECT STD(X1) FROM table_X; but I want to calculate now the STD of the union of data of columns (e.g. X1, X2, ..., X100 of table_X). Does anyone has any suggestion on how to do that? I hoped something as SELECT STD(X1,X2,...,X100) FROM table_X existed, but apparently it does not.
View Replies !
Multiple Parents
I have a table that stores listings, the type of listing can be either an event at a night-club event, at a gig or at a bar. So i could just assign a number to define the type. But, the listing needs to have a parent of either club, gig or bar. What's the best way to handle this? At the moment there are 3 FK-fields that if not set to zero contain the id of either club bar or gig. It somehow doesn't seem right.
View Replies !
PHP Multiple SQL Statements
When i try to do the following in PHP I get errors. Is this not permitted or is this due to a setting somewhere? Can i do only one SQL statement per call to mysql_query? $sql = "CREATE TEMPORARY TABLE tmp SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'; INSERT INTO tmp SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1'; SELECT * from tmp; DROP TABLE tmp;"; $res = mysql_query($sql);
View Replies !
Multiple Row Join?
I have two tables - one called parent, the other called group. table group is made up of ID,parentID,groupHash and groupName. table parent is made up of ID,title,group1Hash,group2Hash,group3Hash (and other columns) Each of the group hashes in table parent correspond to a group hash in table group (ie parent.group1Hash exists in/as group.groupHash and parent.group2Hash also exists (on another row) in/as group.groupHash). This means table parent can have up to three groupHash's noted in a single row and each of these groupHash's will have its name in a corresponding row in table group (using groupHash as key). Can I perform a select whereby I read a row from parent and use its group1Hash, group2Hash and group3Hash to retrieve their corresponding names from table group (all in one select statement)? Or must I perform three or four individual selects to get the desired values from the two tables.
View Replies !
Multiple Results
I'm using PHP to display a list of statistic information about a site. Sometimes I need to retrieve mixed information from the database but I don't know which is the best method to do it. For example I need the top requested html pages and the most repeated value from a column. I dont know if I should make two different queries in the php file or it's more efficient to make only one query with an extra column like id | ip | date | page | max | --------+--------------+----------+----------+---------| 1 + 24.125.24.25 + 24/5/03 + index + 3 | 2 + 24.125.24.25 + 24/5/03 + top + 3 | 3 + 20.12.12.21 + 24/5/03 + index + 3 | 4 + 200.12.24.25 + 24/5/03 + left + 3 | 5 + 24.1.6.255 + 24/5/03 + left + 3 | 6 + 24.125.24.12 + 24/5/03 + index + 3 |
View Replies !
Multiple Sorting ?
In my table i've got a column subject, a column content and a date. I'd like to sort the data first by date, then by topic, and then by date gain, if you see what i mean. I would like to group entries that have the same subject together, sort them by date, and inside each group sort by date as well.
View Replies !
Multiple Sorting
I'm pretty new to SQL and databases, and i've come up with a problem to sort my data. I'm trying to do a basic forum thing. In my table i've got a column subject, a column content and a date. I'd like to sort the data first by date, then by topic, and then by date gain, if you see what i mean. I would like to group entries that have the same subject together, sort them by date, and inside each group sort by date as well. Am i making sense ? Is it possible to do that or am i thinking the whole thing in a wrong way?
View Replies !
Multiple Datadir's
we have several dozen clients and it would be nice to have a seperate folder structure for each one, as we zip up data and send it off to them and we can't have the possibility of accidently sending other clients data. We can have a seperate database for each client, but what would be really nice is to be able to have several different mysql "data" folders (one for each client) but have MySql be aware of all of them
View Replies !
Multiple Domains
have multiple domains on winodws 2003 (IIS) what best way to setup mysql i would like a limit on each domain on the number of databases if possible (see other post), if not i gues i will have to create them i also wish each domain the have phpmyadmin access.
View Replies !
Multiple Masters
The database farm I've set up works great as a single master and two slaves, provided nothing unusual happens to the master machine ... it seems that if logrotate kicks in or the machine reboots, that the mydbhost.001 file in /var/lib/mysql/ increments to 002, 003, etc., but the slaves never update /var/lib/mysql/master.info to point at that new file. Question 1: how do I fix that? Question 2: the software I'm working with does a lot of writing to the database and I'd obviously like to optimize that better than only having a single writeable system. I'm curious whether MySQL on the three machines would manage well if the actual database files were mounted via NFS, or if there's some better method to set up the replication. A few of my Perl scripts have been modified to connect only to "mydbhost1.mydomain.com" for making a $dbh_w handle, and to connect to any of "mydbhost1", "mydbhost2" or "mydbhost3" for reading. But with third-party software, rewrites to look for every SELECT call or every INSERT/UPDATE/CREATE/DELETE call is obviously not going to work out very well.
View Replies !
Multiple Queries W/ 4.0.x (C API)
When executing multiple queries, which return a result set, must mysql_free_result be called after retrieving each result set using mysql_store_result? My concern is that if the result was not freed after each retrieval, that perphaps it may impose a memory leak. Or, does MySql reuse previously allocated memory for subsequent result sets? My app performs several back-to-back select and select/insert queries. Just need to know how to handle this action.
View Replies !
Multiple Choices
I'm building a very simple database but I'm stuck on the best way to achieve a result. Each record represents an object and each object has a color, which is identified by the 'color' field (which is in turn referenced by the 'color' table, with one record per color). Now, some objects may have two or three colors and what I need to do is not only of course entering all these colors (without adding additional color fields, as I don't know how many colors an object can have) but also being able to create queries that lists all objects including their colors and/or queries that lists all object of a specific color or containing a specific color.
View Replies !
Multiple Orders
I have an orders table which has columns: order_id (primary), customer_id, order_amount, num_items etc. I want to count all customers who appear in the table more than once, or more than twice, or any specified number of times. For example I may want to find all customers who have made 6 orders or more. What's the simplest way of doing this?
View Replies !
Store Multiple Ids
I am trying to figure out the best way to organize some tables. This is the problem ID | Name | TransIDs 1 | Bleh | 2,3,5,6 ---- How should I do multple transids? I searched in the forum and most people did this ,2,3,5,6, - which I actually did a couple weeks ago but I don't know if that is the best way to go about it.
View Replies !
Multiple Column
I'm not sure if that's a proper title as using those key words in Google didn't seem to get me the results I needed but it's the best I have right now. I'm going to have a table that will keep track of what users say they're favorite games are. It will link userid to gameid and each user can have multiple favorite games. I could swear I read some where along the way that there's a way to set up the table so it will make sure the combination of userid and gameid fields are unique and therefore won't allow the insertion of the same userid -> gameid values for a single user?
View Replies !
Multiple Counts
Having some trouble with the query below. select a.advisor_ao as 'AO', case c.existing_client when 'feps' then count(c.existing_client) else 0 end as 'total' from advisor_tb a left join company_tb b on a.advisor_id = b.advisor_id left join comp_seminar_ca_tb c on b.company_id = c.company_id group by a.advisor_ao the existing_client field is varchar and contains values in numbers and text. It seems to be returning 0 at all times. But when i set the criteria to 0 and not FEPs that is the only time i get any kind of results. I am not asking for an answer i just wanted to know if my query is incorrect because it is then i have to work on my table structure.
View Replies !
Multiple DISTINCTS
I have a table with LocalNode and RemoteNode columns which may contain multiple identical entries e.g. LocalNode RemoteNode 1...................4 2...................3 1...................5 2...................3 I want produce a result that shows the distinct results from both the LocalNode and RemoteNode columns thus giving 1,2,3,4,5 I know that DISTINCT cannot be used like SELECT DISTINCT Localnode, DISTINCT remotenode, so how do I achieve this
View Replies !
Multiple Order
eg. link1 has 20 'in', 10 out link2 has 20 in, 5000 out link3 has 10 in, 10000 out how can i order it so that it ends up ordering by 'in' DESC then by 'out' if the in are the same, ending up like link2 link1 link3 ?
View Replies !
Multiple Tables Better?
i have a database with 10 tables, each table has around 9,000 record, is it faster and better to put all records in ONE HUGE TABLE and define each table with a column ?? i mean i have table for games, softwares, movies, etc ... so i put ALL the records in one table and make a column named "type" and i insert in each column the corresponding value.
View Replies !
Multiple Value Query
I was wondering how to pull multiple values from a database? So that... SELECT * FROM user WHERE user_id = 2, but also numbers, 3, 4, 5, 6, etc... Do I need to redefine user? SELECT * FROM user AS user1, user AS user2 WHERE user1.user_id = 1 AND user2.user_id = 2?
View Replies !
Multiple Values
I'm working on an application that allows people to publish training information to a database. They have an option to specify how the course is delivered i.e Classroom, Web Based, etc. This is a checkbox value so a single course can be delivered in multiple ways. But what's the best way to store this in the database? The immediate solution that comes to mind is to place all the selected deliveries as comma separated values in the same column. In the corresponding Java object the values will be stored in a String array, and since there won't be a huge number of delivery options it won't be difficult to manage. Is this typical or deemed or a good design though?
View Replies !
Multiple Form Value
I am playing around with an address book mysql database I have put together but am having problems conceptualizing and putting down the search element. I want users to be able to search on more than one field (fields aren't all in 1 table, they're spread out over 5/6 tables) and match all or partially. My brain goes round and round when trying to get a feel for this and keeping the code light and clean. Has anyone had any experience with this and can point me in a useful direction? I have thought about having preset queries that users could select and then find the info they wanted, but it wouldn't allow users to select fields they wanted to search at will, it would be they would have to select a built-in query to run...it's not a bad system, but not flexible, very dependant on me writing the queries.
View Replies !
Multiple Join
I have a query which works, but I would like to know if I can get it to work without having to use 'group by'? If I do not use the 'group by' I get multiple results of the same thing. Code: select C.call_id, C.extn_no, dest, G.group_name from call_data as C, group_user as G left join user_grp as U on G.group_id = U.group_id left join grp_user on C.extn_no = G.extn_no where C.direction = 'Out' group by C.call_id
View Replies !
One Or Multiple Databases
is there any performence-effect whith the way that tables are assigned to databases?? i.e. i have to options to eiter create several databases A, B, C and in each database i have tables x, y, z. instead i also could do only 1 database and call the tables A_x, A_y, A_z, B_x, B_y, B_z, C_x, C_y, C_z. brings me any of those options any performence advantage? I use all tables permanently all day.arranging them in different databases gives me a better systematicly overview. but then i permanently need to switch database.
View Replies !
Get Multiple Entries
I break down my site entries into categories and I enter them as digits 1-9 in the db that correlate with the category. What I'm wondering is if it possible to include multiple entries in one box (such as set the entry as 1,2 for categories 1 & 2) so I don't need to create a second category colum.
View Replies !
|