Query Inside Query?
I would like to know if its practical to Insert a Select statement inside a previous select statements (array).
With that said, the 'inner' select having a WHERE statement thats dependant upon the array results...
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Trying To Avoid Using Query Inside While Loop
I've done a lot of reading on here and I learned from some of Rudy's posts that it's a bad idea to do a query inside a while loop. I don't know why this is but he seems like an expert so I'll listen What I am trying to do is take the top ten points from a player and display them. First I will post the tables then the code. CREATE TABLE `tournament` ( `gameid` int(11) unsigned NOT NULL auto_increment, `gametype` tinyint(2) unsigned NOT NULL default Ɔ', `gamedate` datetime NOT NULL default ��-00-00 00:00:00', `leagueid` int(11) unsigned NOT NULL default Ɔ', `seasonid` int(11) unsigned NOT NULL default Ɔ', `roomid` int(11) NOT NULL default Ɔ', `gamename` varchar(50) NOT NULL default '', `cost` mediumint(4) NOT NULL default Ɔ', `seats` mediumint(4) NOT NULL default Ɔ', `notes` tinytext NOT NULL, PRIMARY KEY (`gameid`) ) ; CREATE TABLE `tournament_results` ( `id` bigint(20) unsigned NOT NULL auto_increment, `gameid` int(11) unsigned NOT NULL default Ɔ', `memberid` int(11) NOT NULL default Ɔ', `place` smallint(4) NOT NULL default Ɔ', `earnings` smallint(5) default Ɔ', `bounties` float unsigned default Ɔ', `points` float NOT NULL, PRIMARY KEY (`id`) ); Now the follow code would be what I would use if I just wanted to add all the points and not limit it PHP mysql_query("SELECT members.firstname, members.lastname, SUM(tournament_results.points) AS tpoints, COUNT(*)as numgames, AVG(tournament_results.points) AS apoints, members.memberid AS membersid FROM members, tournament_results, leaguemembers, tournament WHERE members.memberid = tournament_results.memberid AND leaguemembers.memberid = members.memberid AND leaguemembers.leagueid = '$lid' AND tournament_results.gameid = tournament.gameid AND tournament.seasonid = '$sid' GROUP BY members.memberid ORDER BY tpoints DESC"); That will total all of their games but I want to limit it their top 10 scores how can I do this without introducing a query inside of the while loop?
Accumulating Values Inside A Query
I only have experience of simple queries, and this one is a bit beyond me. I've done some research, and I think it might be possible to do within a single query, but I'm not sure. I have a single table. It contains columns (among others): date, number. I want to produce a table of DATE, and new_number_count, where 'new_number_count' is the number of numbers on day with date DATE that do not have rows on previous DATEs. For example, if this is my table:
Preventing A Count Query Inside A Loop How?
I have an idea in my head and im pretty sure its possible but I don't have enough mysql knowledge to apply. Basically, I have this: SELECT user_id FROM ml_group_subscriptions WHERE user_group = $id then in php I initialise a loop go over the results: PHP while ($row = mysql_fetch_array($get_users)) { $this_user = $row['user_id']; and then an insert query: INSERT INTO ml_subscriptions (`user_id`, `campaign_id`) VALUES ($this_user, $add_to_campaign) while this is all dandy, I don't want duplicate data. My only current method would be PHP $get_users = mysql_query("SELECT user_id FROM ml_group_subscriptions WHERE user_group = $id"); while ($row = mysql_fetch_array($get_users)) { $this_user = $row['user_id']; $check = mysql_result(mysql_query("SELECT COUNT(user_id) FROM ml_subscriptions WHERE user_id = $this_user"),0); if ($check == 0) { $insert_users = mysql_query("INSERT INTO ml_subscriptions (`user_id`, `campaign_id`) VALUES ($this_user, $add_to_campaign)"); } } as you can see this is putting a query inside a loop which could be potentially huge. Can I not adapt the first SELECT query to only accept data that is not about to be duplicated?
Calling A Php Funtion Inside A Mysql Query
hi there, im trying to call a php function that i have created inside a query and im getting an error.when i remove the funtion statment the query is successful. i was wondering is it possible to call a php function inside a query, if so how do i go about doing so. this is my code:
How To Apply Php Or User-defined Functions Inside A Query
Instead of applying a php or user-defined function to data after fetching, I want to apply functions inside queries, not sure if this is possible. This is how it's done with MySQL function: SELECT FROM_UNIXTIME(table_articles.article_pubdate, %M %d, %Y) AS pub_date FROM... Is it possible to replace FROM_UNIXTIME() with the php function date() ? so it's something like SELECT ".date("table_articles.article_pubdate", 'F d, Y')." AS pub_date FROM... The above is just an example, actually I want to apply another user-defined function, which formats text of the field article_content.
How Can I Make A Query Like Microsoft Access, And A Query From A Query
I am new to MYSQL and am trying to understand how to make queries... I am moving from Microsoft Access where it is GUI driven and easy! I can make a simple single query using MYSQL Query Browser, say: qry1: SELECT ID, Area FROM data GROUP BY Area How can I store this as a query inside MYSQL, rather than having to code it each time? In Microsoft Access I could enter a variable ($VARIABLE) and then pass by code to the query: qry2: SELECT ID, $VARIABLE FROM data GROUP BY $VARIABLE How can I store this as a query and then pass the variable from code? In Microsoft Access I could base a query on the results of another query, so following example above: qry3: SELECT qry1.Area, data.ID FROM qry1 INNER JOIN data ON qry1.Area = data.Area; How can I store this as a query in MYSQL.
How To Create Efficient MySQL Query From A Pseudo Query
I'm trying to build a webapplication where users can search for a person having a particular preference for color and material. To store this information I use the following structure (a MySQL dump can be found at the end of this post): *table person with fields: -persid: autoincrement id -name: name of the person *table material with fields: -materialid: autoincrement id -material: name of the material eg "wood" *table color with fields: -colorid: autoincrement id -color: name of the color eg "green" *table persmaterial with fields: -persmatid: autoincrement id -persid: link to table person -materialid: link to table material *table perscolor with fields: -perscolorid: autoincrement id -persid: link to table person -colorid: link to table color In the webapplication the search can be entered by the users as a kind of pseudo query: (color=red OR color=blue) AND color=green AND material=iron My question is: how can I automatically transform this pseudo query into an efficient MySQL query? I have tried out some different options: Option 1: (SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=1 OR pc.colorid=2) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING (count(DISTINCT pc.colorid)=2 AND count(DISTINCT pm.materialid)=1)) UNION (SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=2 OR pc.colorid=3) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING (count(DISTINCT pc.colorid)=2 AND count(DISTINCT pm.materialid)=1)) Remarks: *I do not see how to turn a general pseudo query into a query like the one in option 1, except for turning the pseudo query into a sum of products form where the sulms would correspond to the UNIONs. IS there a clever way to obtain such a sum of products form from an arbitrary pseudo query? Option 2: SELECT persid FROM person p WHERE (EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=1 AND p.persid=pc.persid) OR EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=3 AND p.persid=pc.persid)) AND EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=2 AND p.persid=pc.persid) AND EXISTS(SELECT * FROM persmaterial pm WHERE pm.materialid=2 AND p.persid=pm.persid) Remarks: *very easy to get from pseudo query to MySQL query but what about performance? Option 3: SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=1 OR pc.colorid=2 OR pc.colorid=3) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING sum(case when pc.colorid in (Ƈ',Ɖ') then 1 else 0 end) >= 1 AND sum(case when pc.colorid=ƈ' then 1 else 0 end)>=1 AND sum(case when pm.materialid=ƈ' then 1 else 0 end)>=1 Remarks: *this option requires the pseudo query to be turned into a product of sums form; again is their a clever way to obtain such a form; Option 4 SELECT DISTINCT pc1.persid FROM perscolor pc1 INNER JOIN perscolor pc2 ON pc1.persid=pc2.persid AND pc2.colorid=2 INNER JOIN persmaterial pm1 ON pc1.persid=pm1.persid AND pm1.materialid=2 LEFT OUTER JOIN perscolor pc3 ON pc1.persid=pc3.persid AND pc3.colorid=1 LEFT OUTER JOIN perscolor pc4 ON pc1.persid=pc4.persid AND pc4.colorid=3 WHERE COALESCE(pc3.persid,pc4.persid) IS NOT NULL Remarks: *this option requires the pseudo query to be turned into a product of sums form Option 5: SELECT p.persid FROM person p, persmaterial pm,perscolor pc1,perscolor pc2,perscolor pc3 WHERE p.persid=pm.persid AND p.persid=pc1.persid AND p.persid=pc2.persid AND p.persid=pc3.persid AND (pc1.colorid=1 OR pc2.colorid=3) AND pc3.colorid=2 AND pm.materialid=2 GROUP BY p.persid Remarks: *very easy to get from pseudo query to MySQL query but what about performance? -- phpMyAdmin SQL Dump -- version 2.6.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Oct 19, 2006 at 01:13 PM -- Server version: 4.1.9 -- PHP Version: 4.3.10 -- -- Database: `aston` -- -- -------------------------------------------------------- -- -- Table structure for table `color` -- CREATE TABLE `color` ( `colorid` int(11) NOT NULL auto_increment, `color` varchar(30) NOT NULL default '', PRIMARY KEY (`colorid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `color` -- INSERT INTO `color` VALUES (1, 'red'); INSERT INTO `color` VALUES (2, 'green'); INSERT INTO `color` VALUES (3, 'blue'); INSERT INTO `color` VALUES (4, 'yellow'); -- -------------------------------------------------------- -- -- Table structure for table `material` -- CREATE TABLE `material` ( `materialid` int(11) NOT NULL auto_increment, `material` varchar(30) NOT NULL default '', PRIMARY KEY (`materialid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `material` -- INSERT INTO `material` VALUES (1, 'wood'); INSERT INTO `material` VALUES (2, 'iron'); -- -------------------------------------------------------- -- -- Table structure for table `perscolor` -- CREATE TABLE `perscolor` ( `perscolorid` int(11) NOT NULL auto_increment, `persid` int(11) NOT NULL default Ɔ', `colorid` int(11) NOT NULL default Ɔ', PRIMARY KEY (`perscolorid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; -- -- Dumping data for table `perscolor` -- INSERT INTO `perscolor` VALUES (1, 1, 1); INSERT INTO `perscolor` VALUES (2, 1, 2); INSERT INTO `perscolor` VALUES (3, 2, 1); INSERT INTO `perscolor` VALUES (5, 3, 3); INSERT INTO `perscolor` VALUES (6, 3, 2); -- -------------------------------------------------------- -- -- Table structure for table `persmaterial` -- CREATE TABLE `persmaterial` ( `persmatid` int(11) NOT NULL auto_increment, `persid` int(11) NOT NULL default Ɔ', `materialid` int(11) NOT NULL default Ɔ', PRIMARY KEY (`persmatid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; -- -- Dumping data for table `persmaterial` -- INSERT INTO `persmaterial` VALUES (1, 1, 1); INSERT INTO `persmaterial` VALUES (2, 1, 2); INSERT INTO `persmaterial` VALUES (3, 2, 1); INSERT INTO `persmaterial` VALUES (5, 3, 2); -- -------------------------------------------------------- -- -- Table structure for table `person` -- CREATE TABLE `person` ( `persid` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL default '', PRIMARY KEY (`persid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `person` -- INSERT INTO `person` VALUES (1, 'john'); INSERT INTO `person` VALUES (2, 'emily'); INSERT INTO `person` VALUES (3, 'liz');
Simple Sql Question: Using A Query Result As A Query Variable
EDIT: it works now, I had an error in my code, not my method. I have a very simple question. I have 2 tables: 'users' and 'posts' with the following structure: users: id, username, email_address posts: id, user_id, post_title, post_text in a my own mind's mysql, I would like to: SELECT posts.id, posts.user_id, posts.post_title, posts.post_text users.username FROM users, posts WHERE posts.user_id = users.id I usually do one query for the post data, and then, based on the use_id record, do another of the users table, but today, I'm being forced to do them in one swoop.
Query Based On Results Of A Previous Query
So far I have managed to construct one query which gives me all individuals that have one of three titles. based on this I now want to find all the individuals that are affiliated to those listed in the first query ....
Big Query - Query Not Completely Stored In Memory
I have this query and when executed in mySQL query window throws error that "Big Query - Query not completely stored in memory". Also executed thru app, the program justs hangs. I have checked all indexes, they all look good.....
Pagination W/1 Query + How To Use Query With Indexes
i'm asking 2 questions in 1 thread because i don't wanna take up too much room, hopefully no one will mind. i have mysql 4.1.10 1) i want to find all the rows that were edited this month. the query i currently have ( MONTH(CURDATE()) = MONTH(date) ) doesn't use indexes. how can i manipulate it so i can take advantage of indexes. 2) this is something i've always wondered, but usually just assumed was not possible. if i am listing some results, say 20 per page, how can i get both the total number of results as well as the 20 items required for that specific page. say there are 2 million total results, so grabbing them all and showing just 20 is not an option. if this is not possible what is the most efficient way of making both queries?
Reusing A Query Output In The Same Query
I am guessing a basic question but not one I can find an obvious answer to. If I create a calculated or modified column in a query (such as a modified text string), and then want to reuse that in the same query as I need to do three or four operations on it in sequence, how do I do it in mySQL 4.1? Do I need to create a new column to store the interim result in an existing table (and then clear or alter it each time I run the query), or create a temporary table, or is there an easy way to reuse the query output in the same query (does the query have a name like a table name)? If it requires a new column or table, are there particular disciplines to ensure it is robust and self maintaining?
Create Single Query From Queries On Two Tables (was "Help With Query...")
I read from other thread that query inside loop is not good idea. May I ask some help how can I create a single query to the following code which I use loop. $sql = "SELECT * FROM mytable order by points desc limit 10"; $rec = mysql_query($sql) or die(mysql_error()); $datas = mysql_fetch_array($rec); do{ $sq = "Select * from secondtable where linkid = '$datas[id]'"; $rst = mysql_query($sq) or die(mysql_error()); $rows = mysql_fetch_array($rst); echo "$rows[somefield]"; }while($datas= mysql_fetch_array($rec)); This works perfectly but I want the second query to be out of the loop if there is a way and how.
Grab 'title' From The Table 'forum' Within The Same Query (was "Help With Query")
I have the following query for my vBulletin database: PHP $get_stats_newthreads = $db->query_read(" SELECT thread.forumid, thread.postuserid, thread.postusername, thread.threadid, thread.title, thread.lastpost, thread.forumid, thread.replycount, thread.lastposter, thread.dateline, thread.iconid, thread.views, IF(views<=replycount, replycount+1, views) AS views, thread.visible FROM " . TABLE_PREFIX . "thread AS thread WHERE NOT ISNULL(thread.threadid) AND $weekold<lastpost AND thread.visible!=0 AND (forumid=34 OR forumid=7 OR forumid=8 OR forumid=11 OR forumid=10) ORDER BY rand() DESC LIMIT 5"); and would like to grab 'title' from the table 'forum' where forum.forumid=thread.forumid
Using A Query Result In Another Query
Can I use the results of a SELECT query as a "table" in another query? I want to let my user pick a subset of the data, then refine it further. So ... do I have to repeat all the selection criteria at each step, or can I just do refer to the last query result? If so, what's the PHP syntax for this?
Run A Query On The Results Of A Query?
Lets say I have a query that searches for people living in Colorado. That results in a list on a "results.php" page. Now I want to query that result and search further for people who use Linux. I know I can do this from one query, but I would like to create several checkboxes on my results.php page where I do a further secondary query. Possible? I guess I want to query a query.
Rewriting A Query Without A Sub Query
I've recently changed hosts and found that some of my code broke. The new host is using mysql version 4.0.25 which does not support sub-queries (and they won't upgrade). I'm trying to figure out how to rewrite the following query so it will work on 4.0.25 but not getting anywhere.....
Is It Possible To Run A Query On The Results Of A Query?
I have been trying to figure this out but no luck. Lets say I have a query that searches for people living in Colorado. That results in a list on a "results.php" page. Now I want to query that result and search further for people who use Linux. I know I can do this from one query, but I would like to create several checkboxes on my results.php page where I do a further secondary query. Possible? I guess I want to query a query.
Query 2 Tables For Query
I have 3 tables, products, order_log, and groups. Products is a list of products available, groups are groups that products are put in, and order_log is a log of the current products in an order. I need to sort the order_log by the group the products are in. order_log does not have a group_id in it, however products does. So: SELECT * FROM order_log WHERE product's group_id = 1.
Sub Query And Count Query
i have a database with the following structure id | MoveDate | ItemId | SiteID (a new entry is entered when an item is moved from 1 site to another) and i am trying to forumlate a query so that i can count how many days each item was at a specific location so lets assumes i have the following data 1 | 01/01/2007| 1 | 1 2 | 03/01/2007| 1 | 2 how can i run a query that will tell me that between the dates 01/01/2007 and 08/01/2007 item 1 was at site 1 for 2 days and site 2 for 5
Query From Query Results
I have a report I'm working on that is sort of like google adsense, where it tracks ad clicks and views. I need to provide the option for the user to narrow down the results by date. I have my query worked out, but would it be better for me to run the query again and add the date information to the query, or should I cache the results and then query them? If I were to cache the results and then run queries off that, what would be the advantages or disadvantages? I also have no idea how to go about doing that. Should I create temporary tables to hold the queried information or is there another way?
Inside IF NULL
I have this table: ------------------ id lang name 1 en name1 1 de NULL 2 en name2 2 de name3 I want to return all (WHERE lang='de') rows but if the (name=NULL) then replace it with name from the same id but lang='en'. Is it possible? I have this query: SELECT IFNULL(name, SELECT name FROM table WHERE lang='en' AND id=????) name FROM table WHERE lang='de' Can you fix it?
Looking For Tokens Inside A String
I'm trying to do a weird (?) thing with regexp and MySQL. For example, i have a column with: token1|token2|token3 (three tokens separated by pipes) I'm trying to write an SQL query in order to look for the presence of one of these tokens, that is "look for a string like 'tokenX' that is preceded by the beginning of the line OR a pipe, AND that is followed by the end of the line OR a pipe". I have tried this: SELECT * FROM ... WHERE (... REGEXP "(^||)tokenX($||)"); but, of course, it doesn't work. So my question is: what's wrong ? My regular expression, or my idea ?? There is a another way to obtain what i want, that is to select a token within a string when tokens are separated by anything but a comma ?
COUNT (*) Inside Select
I am doing something wrong i would like to do a count inside this select for example: SELECT th.tid, th.tname, th.tmain (SELECT COUNT(*) as postnumber FROM forumpost AS post WHERE post.ptid=th.tid) FROM thread as th WHERE tmain=1
Use SQL Code From Table Inside Trigger
I have the WHERE clause that I would like to use in constructing larger statements stored inside a database table as a string. Inside the INSERT Trigger for a different table, I would like to be able to: <get the tuple with the WHERE clause I want to use>; SELECT * FROM t WHERE <use code in database>; Is there a way I can pull out this data and append the data to the second statement and execute it?
Format Text Inside Database
I have a news-type database. I pull the data out with PHP. I was wondering if I could format/bold/ certain words in the database when I enter them. For example: Today JOHN CAESAR won his first race. I'd like the name "JOHN CAESAR" to show up bold on my web page. Is there a way to enter it in the database as bold?
Execute A Shell Command Inside SQL
I wonder if there is anyway you can run a shell command inside SQL. for example "SELECT * FROM table;execute shell command" I had googled around and didn't find anything.
Finding User Details Inside UDF
i heared that its possible to get user details inside the UDf by adding the mysql_priv.h header file. But where will this file be available. i am using MySql 3.23.52 on linux8.0 when i try to compile it says :"mysql_priv" file not found. If i can include this file, i can get the thread constructor called...
How To Sort Rows Inside The Group
First step: SELECT ID, Priority, RealID FROM MyTable WHERE ParentID='0' ORDER BY Priority; The result is +----------+----------------+--------------+ | ID | Priority | RealID | +----------+----------------+--------------+ | 1 | 1 | 1 | | 9 | 1 | 1 | | 2 | 2 | 2 | | 11 | 2 | 3 | | 3 | 3 | 3 | | 10 | 3 | 2 | +----------+----------------+--------------+ Then try to obtain the rows grouped by RealID sorted by ID from high to low. This is very important thing and I'm sticking with this: Let's say we have | ID | Priority | RealID | | 1 | 1 | 1 | | 9 | 1 | 1 | I need to obtain second row (the row with max ID in the RealID group). What I worked out is the following: SELECT MAX(ID) as ID, RealID FROM MyTable WHERE ParentID='0' GROUP BY RealID ORDER BY Priority; And Get +----------+--------------+ | ID | RealID | +----------+--------------+ | 9 | 1 | | 10 | 2 | | 11 | 3 | +----------+--------------+ But I'm expecting the following order. +----------+--------------+ | ID | RealID | +----------+--------------+ | 9 | 1 | | 11 | 3 | | 10 | 2 | +----------+--------------+ 1. Can't understand why the rows sorted incorrectly. 2. How to "select" the rows according to my need (I have 10 fields in the MyTable and I think this is not good to select all fields using MAX(...) function). Maybe use subrequests?
Storing The Image Inside Mysql
i read it affect performance by 1 third or something but isnt that worth it for lets say a online hardware store? or is it actually faster maybe?
Html Links Inside Varchar
I have to put html links inside varchar and text fields. They have to be (somehow) fulltext searchable (of course a substring, %keyword% search, would pick them up - I realize that) and they have to render as clickable links when I output the fields via PHP. How would I do this?
Regexp To Return All Number Inside A Field
does this is possible? all i just want to manipulate is the phone number in my database. i want to get the numbers inside this format text (125) 125-1268 or in this format 225.265.4649. how can i accomplish that in the query?
Multiple Prepare Statement Inside The Procedure
I'm trying with the multiple dynamic queries inside the stored procedure means, inside my stored procedure i want to execute Multiple queries (DDL and DML). for that i'm storing query in variable and then executting it by prepare stmt. It works fine with singal prepare stmt and failes for the multiple prepare stmt. Is there any solution to execute multiple queries inside the Stored procedures or Functions?
Ignoring Content Inside HTML Tags
Is it possible to set MySQL to by default ignore all content contained within HTML tags? For instance, if a database full of HTML pages has the "class" attribute on a lot of the tags and someone searches for "class" expecting information on classes, wouldn't that also return all those documents just because they had a "class" attribute? It would be great if I could set MySQL to ignore all content between < and >.
Store Links Inside The Main Text In A Database
we are trying to set up a mySql database while rebuilding a webpage with lots of content.we actually dont know how to set up the tables for that and especially how to store links inside the main text?should we use xml files to store the text with embedded links?
Mad Query
Hi every body I have this query in multi tables select t.id, t2.id from table t, table2 t2 where t1.id = t2.id the result is t1, t2 1 3 1 6 1 8 2 4 3 5 3 8 3 3 ... ... .. I need to make it t1 , t2 1 3,6,8 2 4 3 5,8,3 .... ... is there anyway to make this query?
Can This Be Done In One Query?
I have the following two tables: article: article_id, subject_id_1, subject_id_2, subject_id_3 subject: subject_id, subject_text subject_id_1, subject_id_2, subject_id_3 are the subject_id in subject table for article_id 5, I want to get all the subjects, i can do this with 3 querys: for subject 1: select subject.subject_text from article, subject where subject.subject_id = artible.subject_id_1 and article_id = 5. for subject 2: select subject.subject_text from article, subject where subject.subject_id = artible.subject_id_2 and article_id = 5. for subject 3: select subject.subject_text from article, subject where subject.subject_id = artible.subject_id_3 and article_id = 5. Is there a way to do the same thing with one query?
Query Help Please?
Completely puzzled by this one and wondered if someone could help I have three tables: A players table: A appearances table: A goals table: Now here's what I want to: - look at all records in the goals table - Get the values from player_one_goals, player_two_goals etc... - Match it against the appearances table ie: player_one=player_one_goals ie player with id= 2 scored 1 goal. - Then find the player_name value of player_one by matching the value of the player against the player_id in the players_table
Need Help With A Query
Ok, I can't get this to work.. this is my database: id nav1 nav2 1 company jobs 2 company this 3 company that 4 services foo 5 services bar 6 services blabla now i want to select company, jobs and services, foo so i want to select each nav1+nav2 pair with the lowest id (id1 and id 4 in this case) makes sense?
Help With Query
So I have two integers, start and limit. I also have a table: ----------------- days ------------------ id sa01 sa02 sb01 sb02 sb03 sb04 sb05 sb06 sb07 sb08 sb09 sb10 sb11 sb12 sb13 sb14 sb15 sb16 sb17 sb18 The id column is a standard auto_increment primary key, whilst all the other columns are unsigned smallints that default to 0. Basically, I want to select every s* column that is 0 (or any given number) from the rows with id's between the start and limit. So kinda merging this query: SELECT * FROM days WHERE id >= 2 AND id <= 200 and this pseudo- PHP row_as_array = db_resultforeach (row_as_array as key => value) if (value == 0) // action else // we didn't need this column
|