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




Two Table Query: Grab Rows From One Table Even If No Related Row In Other Table


PHP

$gettray = mysql_query("SELECT trailers.title,
trailers.link,
trailers.movie,
movie.title AS mtitle
FROM trailers,movie
WHERE trailers.movie=movie.word
ORDER BY trailerid
DESC LIMIT 6",$connm);

It works great, but there is one problem. It will not grab any rows from the 'trailers' table if a corresponding movie row does not exist in the 'movies' table.

I want it to pull ALL rows from the 'trailers' table, even if the corresponding row in the 'movies' table does not exist yet.

If the row does not exist in 'movies', the program than uses the entire trailer title like so


PHP

if($ttray['mtitle']) {
  $newttitle = explode("-",$ttray['title']);
$newttitle = array_reverse($newttitle);
$ttitle = $newttitle[0];
$ttitle = $ttray['mtitle'] ."- ". $ttitle;
} else {
$ttitle = $ttray['title'];
}



Thanks
Ryan




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Updating Rows In Table B Based On Related Field In Table A
Ver 4.1.8-standard for apple-darwin7.6.0 on powerpc (Official MySQL-standard binary)

I am trying to do some data migration based. I have several tables that contain our legacy pkey field and I want to update the tables with new ID's.
I need to do this several times and have tried it several ways to no avail.

Table A
---------
companyID int(10) pKey
legacyID int(10) old legacy pkey

Table B
---------
bAID int(10) pkey
companyID int(10)
legacyID int(10)

Table A has values for both companyID (unique key) and legacyID.
Table B has values for bAID (unique key) and legacyID but companyID is empty.

I need to update tableB.companyID with tableA.companyID based on tableb.cSerialID to tablea.cSerialID relationship.

I need a query that will update ALL rows.

Multi Table Query, Grab More Than Single Row From Secondary Table
I have a query like so:

PHP Code:

$selectt = mysql_query("SELECT trailers.trailer_id,
trailers.trailer_title,
trailers.description, trailers.file_url,
trailers.runtime, trailers.views,
trailers.rating, trailers.tt, trailers.keyw, trailers.date,
tags.snub,
films.film_title, films.studio, films.keyw, films.image
FROM films,tags,trailers
WHERE trailers.trailer_id=tags.trailer_id
AND trailers.film_id=films.film_id
ORDER BY trailers.trailer_id DESC LIMIT 8",$dbh);


I know this is pretty sloppy, I have multiple 'tags' per trailer ID, and I was hoping to grab all of them in a single query; maybe into an array? So that it shows the row, and then all the tags that belong to it.

Possible?

Getting Rows That Are Related To Other Rows In The Same Table
I use a table to save a map using the following structure:

id, x, y, owner

Every occupied map filed has an owner id != 0. The owner id is = 0 for vacant fields.

now the problem:

New registered users need a vacant field on the map. Moreover the mapfields around this field need to be vacant as well! (sqrt((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y)) <= 5.25)

What I need is a query that gets those fields that have vacant fields around them.

So far, all my tries to solve this problem with Joins/Suvqueries failed.

Help With 3 Table Query &amp; Counting Rows In Third Table
I have three tables, a members, a vendors and a products. I'm using a query to grab all of the rows from the first two tables, matching on a primary key. This is easy and works fine. However, I'm trying to pull the number of products from the third table and it's giving me trouble. Basically, I can count the products for each vendor if products exist, but if there are no products, instead of returning 0, no rows are returning.

current query looks like this:

SELECT t1.*, t2.*, count(*) AS count FROM vendors as t1, members AS t2, products AS t3 WHERE t2.mem_id = t1.mem_id AND t3.vendors_id = t1.vendors_id GROUP BY t1.vendors_id;

So, all of the vendors that have zero products are being left out of the results. Does anyone know if it's possible to achieve this without using a temp table?

Query The Article Table And Get A Count Of All Related Comments
Could someone please help me with this query. I have two tables -- one for my articles and another for my comments. Comments are stored in the comments table with a corresponding article id.

I want to query the article table and get a count of all related comments. The following query doesn't seem to work for me. Can you please suggest how I fix it?

SELECT a.id AS id, a.title AS title, a.preview AS preview, a.thumbnail AS thumbnail, a.category AS category, a.timestamp AS timestamp, a.game AS game, count( b.id ) AS commentcount
FROM article_table AS a, comment_table AS b
LEFT JOIN comment_table ON a.id = b.article
WHERE a.news = 'Yes'
AND a.type = &#391;'
AND a.saved != &#391;'
GROUP BY b.article
ORDER BY a.timestamp DESC
LIMIT 5

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

Grab All Users Not In Second Table.
I have two tables. I want to grab all the users from the users table who are not found in the second table. It's just seems to be one of those days where I can't perform the simple tasks, I think I need to go back to bed.

[table] users
[field] userid

[table] user_details
[field] userid

Select userid from users where userid not in user details

Grab The Highest ID From A MySQL Table
I have a MySQL table on my web server (external web host) that has an
auto-increment integer as it's primary key field.

Is there a quick PHP function that will get me the highest ID in the table,
that is, the ID that belongs to the last record added.

Note, I need it to work across and between connection session, not from
within the same connection session.

Delete Rows From Table A, Which Dont Exist In Table B (base On Column X)
I have 2 tables identically structured.

A & B

Table A, has column: Product (product code) as primary key

Table B doesn't.

Apart from that they have the exact same fields.

There's also a column: supplier

I want to

Delete * from table A, where does not exist in B (based on column: Product) & where supplier = apples

So to elaborate. Table A is my main table, but it now contains outdated products from supplier apple. Table B has the latest list of products from supplier apple. So I want to remove old products from A that supplier apple no longer makes.

mysql version 4.0.27

ALTER TABLE Deleted The Rows - Error: Table Is Full
Today when I tried to insert data in a table i received the error that 'table is full'. On SHOW TABLE STATUS, I noticed the size of table is grown to 4GB (rows 5359211).

mysql> SHOW TABLE STATUS LIKE 'messages' G
*************************** 1. row ***************************
Name: messages
Engine: MyISAM
Version: 9
Row_format: Dynamic
Rows: 5359211
Avg_row_length: 801
Data_length: 4294967288
Max_data_length: 4294967295
Index_length: 45783040
Data_free: 0
Auto_increment: 5406252
Create_time: 2007-04-20 18:26:38
Update_time: 2007-08-22 09:55:22
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
Here is the table structure.


CREATE TABLE `messages` (
`id` int(11) NOT NULL auto_increment,
`subject` varchar(255) NOT NULL default '',
`message` text NOT NULL,
`attachment_path` varchar(255) default NULL,
`new` tinyint(4) NOT NULL default &#390;',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

On searching I found the this link.
http://dev.mysql.com/doc/refman/4.1/en/full-table.html

According to manual i executed the following query

MySQL
ALTER TABLE messages MAX_ROWS=20000000000;
I skipped AVG_ROW_LENGTH from the query, I was confused what should be the value for this.

After executing the query, when i check the table status it displayed totally different picture. Now there were only 170109 rows left.


mysql> SHOW TABLE STATUS LIKE 'messages' G
*************************** 1. row ***************************
Name: messages
Engine: MyISAM
Version: 9
Row_format: Dynamic
Rows: 170109
Avg_row_length: 649
Data_length: 110563036
Max_data_length: 281474976710655
Index_length: 1961984
Data_free: 0
Auto_increment: 5409214
Create_time: 2007-08-23 10:07:08
Update_time: 2007-08-23 13:41:57
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options: max_rows=4294967295
Comment:
1 row in set (0.00 sec)
What could be the reason of this rows deletion?

I am on 32 bit system.
MySQL version: 4.1.18-standard-log
Operating System : CentOS 3.x
Memory: 4 GB DDR

Table Design Question? House Table, Owner Table, Code Violations Table - Best Way?
Given the tables:

HOUSE
house_ID
address

OWNER
owner_ID
name
telephone...

HOUSE_OWNER_JOIN
?

CODE_VIOLATION_HISTORY
house_ID
violation_ID
violationStatement
...

My goal is to be able to track code violations of the house PER owner.

For example, I need to display a page that shows the current house with it's coe violations and a link to show the HOUSE's history of violation regardless of owner, Like:

House 1009283
Address
Past history (link to the following)

House History
2001-01-04 Owner: John Smith Code Violation: Gutter issue
1999-06-01 Owner: John Smith Code Violation: Faulty Steps
1998-03-02 Owner: Sam Spade Code Violation: Driveway carcks
1990-01-12 Owner: Keith Sledge Code Violation: Grass untidy


For the design of the HOUSE_OWNER_JOIN table, I thought of two ways I could go on this and this is where I need your help.

Option 1:
Have the HOUSE_OWNER_JOIN table keep dates so I can track the ownership changes that way:

HOUSE_OWNER_JOIN
houseID
ownerID
dateOwnershipBegan
dateOwnershipEnded

then I could look up all code violations by date and associate them with their rightful owner.

==================================================
Option 2:
Have the HOUSE_OWNER_JOIN table be the primary keeper of identity data by adding a new primary key and changing the CODE_VIOLATION_HISTORY table to reference that table by chaning the referencing key from house_ID to house_owner_ID:

HOUSE_OWNER_JOIN
house_owner_ID
houseID
ownerID
dateOwnershipBegan
dateOwnershipEnded

CODE_VIOLATION_HISTORY
house_owner_ID
violationStatement
...

Simple Fast Way To Grab The Highest ID From A MySQL Table?
I have a MySQL table on my web server (external web host) that has an
auto-increment integer as it's primary key field.

Is there a quick PHP function that will get me the highest ID in the table,
that is, the ID that belongs to the last record added.

Note, I need it to work across and between connection session, not from
within the same connection session.

Related Table
I am trying to follow an example I found for creating two tables in a "related form" The code creates the two tables, however if I use PhpMYadmin to enter primary records in the first table, I get an error on trying to add a second record. Code:

Average Query With 2 Rows From Same Table
My table:
"answer"
answerID
answer(int)
questionID(int)
userID(int)

answer1 is questionID = 1
answer2 is questionID = 2
WHERE userID is the same for both answer1 and answer2

I want the average of answer1/answer2: AVG(ans1/ans2), but how?

DELETE With Related Table
I have a table (tableA), with a data field (saved as a VARCHAR in
YYYY-MM-DD). I have a second table, tableB, which has a field with an int
field which refers to the ID of tableA (or is null). I call this field
tableB.idA

I am trying to delete rows in tableA where the date is less than a specified
value AND there is no reference to said row in tableB.

But how to specify this in SQL. I tried :

DELETE FROM tableA WHERE tableA.date <'2007-01-01' and tableB.idA!=
tableA.id;

only to get the exception Unknown table 'tableB' in where clause.

Forum Related Table Structure
I didn't know whether to post this in the php forum or mysql--we'll try this one:

Suppose that I have a mysql-php based forum running. Users table (simplified) looks like:

Users
------------
user_id (int, primary_key)
username (varchar(30))
password (varchar(30))
read_post_ids (text)


Currently, 'read_post_ids' is a comma-separated list of all the post ids that a user has clicked on, which are marked as such.
Currently a php script is resposible for reading the list into an array, looping through to find values if needed, and on a write back to the db it takes the array and turns it back into a CSV string.

Problem: The table isn't even in 1NF because of this field, and extra processing is going on. As an alternative, I have considered dropping 'read_post_ids' from this table, and starting a new table:

Read_Post_Ids
-------------
id
read_post_id
user_id

This normals the tables and makes queries easier, but I worry about storage. Let's say I have 10,000 forum users, that on average read 20 posts per day. that is 200,000 table rows per day. In a year, I have 71,000,000 rows. If I index the fields (as I probably should for speed), the rows take up even more room. If I decide to only allow a user a maximum of 300 stored 'read posts' (for example), then I probably have to add a timestamp field so I can delete the older ids, which takes up even more space.

So is there a preferred method here? I would prefer that the tables be normaled, but I worry about the table growing out of hand in terms of size, and at some point becoming slow.

Counting Records In Related Table
I'm trying to construct a single query that returns all records from one table plus a count of all corresponding records in another table. I have a table of members (members) and a separate table (traffic) that tracks what each member has downloaded from the website I've created. Here is the current SELECT statement I'm using:

SELECT * , COUNT(*) AS traffic_count
FROM `members` , `traffic`
WHERE members.id = traffic.member_id
GROUP BY members.id
ORDER BY traffic_count

This almost works for me. The problem is that it only returns results for the members who have corresponding records in the 'traffic' table. This is a great start but I'm trying to return all records from the 'members' table including a corresponding 'traffic_count' variable for each member. This means that for each member that has no entries in the 'traffic' table I'd like the 'traffic_count' variable to be 0.

Count One Table's Rows From Multi Table Query
here are my tables (condensed)

FEEDS
feed_id
site_id

SITE
site_id
site_name

ARTICLES
article_id
feed_id
link

I want to create a query that returns the total number of articles for every site_id (which is unique in the SITE table). I have this:

PHP

$gsite = mysql_query("SELECT site.site_id, feeds.feed_id, COUNT(articles.article_id) AS acont FROM site,feeds,articles
WHERE feeds.site_id = site.site_id AND articles.feed_id = feeds.feed_id group by site.site_id", $connection)
or die(mysql_error());

The query does not use JOIN, ON and all that good stuff.

I just need the following variables to run through a loop:

site_id
the number of articles rows per site_id

Create Virtual Table During Query Or Load Table To Memory From Text File
I have access to my application database via a secure link, so I cannot link a local database to it, only run queries on the remote server and download the result.

The database is missing some useful information, and I cannot add a table at this stage. I would like to achieve the result by creating a virtual table or the like. ...

Deleting Rows In One Table That Don't Have A Corresponding Row In Another Table.
I have two tables:

Table: Users
UserName (primary key)
Password
PurgeDate

Table: Logins
UserName
LoginDate

I want to do two things:

1) Delete all records from the Logins table where the value of UserName cannot be found in the UserName column in the Users table.

2) Records are purged from the Users table based on the PurgeDate. When that happens, I want to purge all records from the Logins table where UserName has the same value as the value in UserName in any record purged from the Users table.

Rows Of A Table As Columns Of Another Table
with the following tables i have the problem written below:

table group
gr_id, name

table gr2kr
id, gr_id, kr:id

table krit
kr_id, name

now i don't want to get an output like

name1 krit1
name1 krit2
name2 krit1

i want something like this
name1 krit1 krit2
name2 krit1

does anybody have an idea how or if it is possible?

Copy Rows From One Table To Another Table
One is the "main" machine and all the others will synch data up with it it once in a while. Is there a command to insert rows into one table on a different machine using the table on the current machine? Like....

Main Table 1 on main machine e.x. 192.168.1.1
name|email|listdate
------------------------
tom|a@b.com|1-1-2005
dick|c@d.com|1-1-2005
harry|e@f.com|1-1-2005
etc.



Temp Table 1 on field machine e.x. 192.168.1.2
name|email|listdate
-----------------------
larry|g@j.com|6-1-2005
mike|h@k.com|3-1-2005
fred|i@l.com|5-1-2005


i know you can do something like the following if they are both located on the same machine but i don't know how to structure the command for different machines:

insert into real_table (col1, col2) select x, y from temp_table;


1 Simply Query Problem. Please Help With Insert Into 1 Table From Another Table
I have Table A that has some records already in and then I have Table B that does a few things and gets updated regularly.

With Table A, I want to get it updated every 8 hours or so with new data that has been inserted into Table B.

I will do this using the Cron.

But what would be the best insert query to use so that it does the process really quick.

The query that I have so far is:

Quote:

mysql_query("INSERT INTO table a (id, title, descrip) SELECT id, title, descrip FROM table b where app=1");

With the above query the id's match in both tables. But I only want the new records to be inserted into Table A where app=1 in Table B and the row is not already in Table A.

How can I add to the query so that it does this.

Query Table A And Return Records Not Found In Table B.
Given table A and table B.  Table A is a master table and table B is a list of authority or reference which is fed by selecting records from table A (via an UI I wrote in PHP).

The interface is working fine but I am left with one problem.    If I need to edit my table of authority, the source table (table A) should return ONLY entries not previously selected.

That said, if the A.key is in B.key, records from table A matching B.key should be omitted.

I could do this by looping through the query results from table A and querying table B, if no match, show A.key.  This I think is a bit antiquated and possibly too involved.

Is there a joint query command I can use?

Match Rows In Table B With Rows In Table A
How do I structure a query to match rows in table B with rows in table A where column in B contains strings that contain data from column in A..

Example:

B.part = "abcdefg" matches A.part ="cde"

I cannot put literal in query.. it must be from column data..

It's easy to match rows where columns are equal, but I can't figure out how to get a match with "substring" as shown.

How To Get Top 8 Rows From A Table
I have a table with the fields xId, yId and count. count is an int from 1 to n. I would like to get the 8 rows that has the highest count. Like 983, 980, 850, 843.. and so on. Also I want the 8 highest counts grouped with yId.

That was a pretty simple query I found out. I read about it here:
http://www.plus2net.com/sql_tutorial/second-highest.php

Set Of Rows From A Table
I have a table which has 2000 rows, I want to take a sample set of rows (500) and interested in four column values (out of total 10 columns), one column value amongst this is most important and have multiple type of value, i want my sample to reflect each type of value (single digit, multiple digit, alphanumeric etc).
right now i have absolutely no idea how to do it, and i want it done soon.

How To Clear All Rows In The Table?
I wonder how can I quickly delete all row in the table? Can I do it just with one query without dropping table and creating new one?

Maximum Rows In Table
I heard there's a max of about 65k rows not counting longtext and blobs in a mysql table

How does longtext and blobs affect the max row count? And, what happens if you go over the max rows -- does the table auto-trim or does everything blow up? (Sorry... too scared to try myself )

Combining Rows In Table
I'm not sure if this can be done in MySQL, but i'll ask anyways..

id Name a b c d
------------------------------------------
1 Same 1 0 0 1
2 Same 0 1 0 0
3 Same 0 0 1 0
4 Sametwo 1 0 0 0
5 Sametwo 0 1 0 0
6 Samethree 0 0 1 0
Is there a way to turn this table into:


id Name a b c d
------------------------------------------
1 Same 1 1 1 1
2 Sametwo 1 1 0 0
3 Samethree 0 0 1 0
Trying to clean up legacy databases and it's proving to be quite painful..

Select Every 3 Rows From A Table.
I have a bit of a problem, Iam doing a match results page with data from mysql.

My table Name: JuniorMatchResults

Data Colums: id, date, venue, position (1,2 or 3), weight.

What i wanto to do is output this information in my website such as you would have the 1st 3 positions outputted in a table, the the next set of 3 in a table and so on.

Delete The First Rows In A Table
How i can do to delete all rows in a table less the last three?
ex.
id name
1 cccf
2 ccce
3 cccd
4 cccc
5 cccb
6 ccca

The query delete all row less
4 cccc
5 cccb
6 ccca

Move Rows From One Table To Another?
Is there a direct way to move a row from one table to another?

Or do I need to go while through the original table, insert a new row in my new table, then remove it from the old table?

Can I Create A Table With 1.8*10^11 Rows?
I'm trying to create a table with 1.8*10^11 rows? Is it possible with
mySQL v4?

Selecting Rows Not Within Another Table
I have 2 tables Stores and Store_Projects that im trying to pull all
stores not in certian projects but belong to a customer. Heres the
design of each

CREATE TABLE `Stores` (
`storeID` int(10) unsigned NOT NULL auto_increment,
`storeMetro` int(11) NOT NULL default '0',
`storeManager` int(10) unsigned NOT NULL default '0',
`storeState` int(10) unsigned NOT NULL default '0',
`storeAddress` varchar(100) default NULL,
`storeCity` varchar(50) default NULL,
`storeZipcode` varchar(20) default NULL,
`storePhone` varchar(20) default NULL,
`projectStatus` varchar(20) default NULL,
`storeSupervisorName` varchar(100) default NULL,
`storeSupervisorPhone` varchar(20) default NULL,
`storeSupervisorEmail` varchar(255) default NULL,
`storeOtherContactName` varchar(100) default NULL,
`storeOtherContactPhone` varchar(20) default NULL,
`storeOtherContactEmail` varchar(255) default NULL,
`storeNumber` varchar(50) default NULL,
PRIMARY KEY (`storeID`),
UNIQUE KEY `storeID` (`storeID`),
KEY `storeMetro` (`storeMetro`)
)

CREATE TABLE `Store_Projects` (
`projectID` int(6) unsigned zerofill NOT NULL default '000000',
`storeID` int(11) NOT NULL default '0',
`billRate` varchar(10) NOT NULL default '0.0',
`associatePayRate` varchar(10) NOT NULL default '',
`repsNeeded` smallint(6) default NULL,
`storeServiceDateDay` smallint(2) unsigned default NULL,
`storeServiceDateMonth` smallint(2) unsigned default NULL,
`storeServiceDateYear` int(4) default NULL,
`receivedPayment` enum('Y','N') NOT NULL default 'N',
`invoiceNumber` varchar(25) default NULL,
`invoiceDate` date default NULL,
PRIMARY KEY (`projectID`,`storeID`)
)

I had designed the query like this

SELECT st.*, s.stateInitials, m.metroName, sta.stateInitials AS
metroState
FROM Stores AS st
LEFT OUTER JOIN CustomerUsers AS cu
ON cu.userID = st.storeManager
INNER JOIN States AS s
ON st.storeState = s.stateID
INNER JOIN MetroAreas AS m
ON st.storeMetro = m.metroID
INNER JOIN States AS sta
ON m.stateID = sta.stateID
INNER JOIN Store_Projects AS sp
ON sp.storeID = st.storeID
WHERE st.customerID = 4
AND sp.projectID != 000002

But of course thats not going to work if the store is not in the
Store_Projects table which it wouldnt be if its not in a specific
project. So I need a way to pull all Stores with a specific customerID
but is NOT in the Store_Projects with a specific projectID.

Can anyone explain how this should be done within the query? I could
do it by creating an array and then processing out all the stores but
I would much rather let MySQL do the work for figuring this out.

Selecting Rows Not Within Another Table
I have 2 tables Stores and Store_Projects that im trying to pull all
stores not in certian projects but belong to a customer. Heres the
design of each

CREATE TABLE `Stores` (
`storeID` int(10) unsigned NOT NULL auto_increment,
`storeMetro` int(11) NOT NULL default '0',
`storeManager` int(10) unsigned NOT NULL default '0',
`storeState` int(10) unsigned NOT NULL default '0',
`storeAddress` varchar(100) default NULL,
`storeCity` varchar(50) default NULL,
`storeZipcode` varchar(20) default NULL,
`storePhone` varchar(20) default NULL,
`projectStatus` varchar(20) default NULL,
`storeSupervisorName` varchar(100) default NULL,
`storeSupervisorPhone` varchar(20) default NULL,
`storeSupervisorEmail` varchar(255) default NULL,
`storeOtherContactName` varchar(100) default NULL,
`storeOtherContactPhone` varchar(20) default NULL,
`storeOtherContactEmail` varchar(255) default NULL,
`storeNumber` varchar(50) default NULL,
PRIMARY KEY (`storeID`),
UNIQUE KEY `storeID` (`storeID`),
KEY `storeMetro` (`storeMetro`)
)

CREATE TABLE `Store_Projects` (
`projectID`.........................................

Duplicating Rows In A Table...
Here is my select query:

$getCourseQuery = "SELECT sC.*
FROM studentCourses sC, profileChapters pC
WHERE sC.courseCode = '$_GET[ref]'
AND sC.studentPntr = '$_GET[pntr]'
AND sC.chapterPntr = pC.pntr
AND pC.assessmentType = 'chapterReview'";

I want to take all of the rows that were selected and duplicate them with a new studentPntr. Is there an easier and cleaner way of doing this than putting all of the fields and all of the values into the insert query? There are 23 fields in the table and I don't want to have to type them all out if I don't have to.

Delete Everything From Table Except The Top 100 Rows
Does anyone know the mysql syntax to delete everything in a table except the top 100 rows?

Do you need to use LIMIT?

Select Rows Not In Second Table
I want to select all records in a "User" table that are not in the "Groups" Table.

Select
users.USERID,
users.NAME
From
users
Outer Join groupmembers ON users.USERID = groupmembers.empid
Where
groupmembers.groupid <> '9'

In therory this would return me all users not in group 9, but I am getting an error in my SQL... I dont really understand Left - Right - and Outer joins but I have tried all three... I could do this in 3 queries - Create a Temp Table - Delete Records w/ 9 in group ID ... Select remaing records.... But there must be a better way...

Counting Rows From Other Table
SELECT one.this, COUNT(two.this) FROM one, two WHERE (two.this = one.this)The problem with this query is that it won't return rows from table "one" if they don't match with at least one element on table "two". How to proceed then with just one query?

Selecting All Rows From One Table That Is Not In The Other
What I want to do is this:

select table1.id from table1,table2 where table1.id != table2.id   ....  I wish it was possible to write like that... but it doesn't I guess I can figure out the reason but anyway how should I do it? PLEAse help... example:

table1    table2
id 1      id2
id 2
id 3

select table1.id from table1,table2 where <what to write here?>

result:
id 1
id 3

Table: Max Number Of Rows
In a table what is the limit to the number of rows that make it up?
Is the only limitation HardDrive space?

Counting Rows In A Table
Anyone know how to count rows in a table depending on 2 columns, and
different values within the second column.

Basically i am trying to obtain the resultset example below from the table
example below

TABLE example:

Date | Status
-------------------------
2003/07/01 | 1
2003/07/04 | 1
2003/07/06 | 1
2003/07/24 | 2
2003/07/24 | 2
2003/07/24 | 1

RESULTSET required:

Date | Status = 1 | Status = 2
-----------------------------------------------
2003/07/01 | 1 |
2003/07/04 | 1 |
2003/07/06 | 1 |
2003/07/24 | 1 | 2

Number Of Rows In Table
Is there a query which returns the number of rows in a table without using a "SELECT..." followed by recordset.RowCount?

Reorder Table Rows
if there is a easy way to permanently and randomly reorder the rows in a table? I want to randomise my results but in a way that they are consistent when people do a search. This seems to be the only way to do it.

Number Of Table Rows
I have tried to answer this question by using Google but my search didn't bear any fruits, so to speak.

I am in the middle of designing my db and i have just thought that in some of my tables i think i will have 1000s of entries [rows] and if my web application with a db backend is successful it can turn into millions of rows [wishful] - so i wanted to know is there a limit in the number of rows for a table? I think not, but how will performance be effected?I am using a MySQL database, I am using a linux server not sure if this matters but microsft and i dont get along.

Find Rows In One Table
I am setting up an osCommerce store and have discovered that some products do not have corresponding entries in the categories table. I need to find these items (there are roughly 5000 items) so that they can be fixed.
These are the relevant tables:

Table Name: products
Primary Key: products_id

Table Name: products_to_categories
Primary Keys: products_id and categories_id

I need to find all rows in products that do not have a corresponding entry in products_to_categoriesIs this possible?

1 Table For Millions Of Rows
I have one table which may record possibly millions of hits and i want to know if this is a good idea?


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