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


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





Master List Of Select Rows


I am creating a database as part of a service record for items. When an item is serviced, an entry is added to the database with the item serial number and some other info. That all works great.

I also want to create a master list of all items. If I use the old "SELECT * FROM database WHERE 1" query, it will display all the rows in the database. Is there any way to retrieve the last row for each item number, instead of displaying all rows for all items? It seems I have worked myself into a corner with this table setup. If it can't be accomplished the way I have it set up, is there a better way to structure the table?

I thought about creating another field "type" and have it be either "parent" or "child" and then only display the "parent" rows in the master list. That would involve two queries when updating an item's status (adding a new row and updating the "parent" row for that item), and seems to be less convenient.

This seems like a common application so there has to be another way.




View Complete Forum Thread with Replies

Related Forum Messages:
Query For Month Data Based On Occurance Against Master List
I have a query running nicely. Now I'm trying to expand it.

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

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

View Replies !
Master Master Replication, Truncate Table Fails, Version 5.0.22
I have set up a master master replication link between two databases, prototyping an idea. Anyhow, adding records and deleting works, both get updated, creating and dropping tables works, but truncating tables doesn't work.

My main questions are, why doesn't truncate work, and if it doesn't work, what else doesn't work across a master-master replication link?

View Replies !
Backing Up A Circular Master-master Replication Setup
I have a running circular master - master replication running.

I want to run a mysqldump on one of the servers but am worried what the impact of running a mysqldump will be on the replication.

Will the transactions generated by the mysqldump get put into the binary log file?

I see the option --delete-master-logs for mysqldump and am assuming that it deletes the previously inserted log items from the binary log file.

If there is someone that can please just give me a little more clarification on how the --delete-master-logs option works.

View Replies !
Getting Rows Multiple By List Query
I have a list of values (constants) that I use to find matching rows in a single table as follows:

"select id, name from articles where id in(1,2,3,2,3,2,2)"

seems very simple, but my problem is, the query delivers only 3 lines, of course, because the last four numbers are redundant.

But my need is, to get a row for each number in the list, wheather it is doubled or not.

View Replies !
How To Find All Rows Where Id Is One Of A Long List Of Ids?
I have a long list of "id" values: id1, id2, id3, etc.

I want to find all rows in a table where the id is in the list.
In other circumstances, I want to find all rows where the id is NOT in the list.

Is there a more concise query that the following?

SELECT * FROM table WHERE id=id1 OR id=id2 OR id=id3 OR ...

For instance, I can't find a syntax that looks like this:

SELECT * FROM table WHERE id IN (id1,id2,id3,...)

Also, ... if the list of id values is the result of a previous SELECT query,
is there a way to save that result and use it in a subsequent query?

View Replies !
Master / Master Asynchronous Replication
Currently we have a web based application that is mostly reads (4:1
r/w). It is using a single MySQL database server. Is there any way to
have two database servers in a master/master configuration such that
writes to either database server are replicated to eachother. Basically
even though we have a 4:1 ration of read/write the writes happen often
enought that when the database goes down the app stops working. I know
how to get this working in Oracle (insert big laugh here) but Oracle is
cost prohibitive. Any pointers?

View Replies !
Master/Master Replication Problems
I was wondering whether someone could help me.

I have inherited set of replicated servers from a guy I used to work with, basic set up is:

Master1/Slave2 - Server ID 1
Master2/Slave1 - Server ID 2

When I looked at the logs it looks as though Server ID 2 is well out of step. Having looked at the slave status it appears that that Slave_SQL_Running state is set to No and a particular piece of SQL is causing the problem. Having ran the SQL on the particular server it has now problem at all.

Now my understanding of this type of set up is that Server ID 1 writes directly to Server ID 2, then Server ID 1 is in turn replicated to.

But for the life in me, I cannot understand why this piece of SQL is causing the problem. Can anyone offer me any ideas on how I can best get to the bottom of this, I'm really struggling with this. There was me thinking replication just worked!

Is there an ability to get MySQL to log all queries it is running, so I can get to the bottom of all queries currently being executed?

View Replies !
SELECT From An Unsorted List
Is there a way to sort a table by a certain criteria and then getting the positions of a specific data set?

E.g. I have a list of employees and want to sort them by birthday and then want to know who's second, third or 105th in the year.

View Replies !
SELECT Result In A List
I've a lot of values in a table and they are referenced with a id:

+----------+----------- +
| id | value |
+----------+-----------+
| 1 | aaaaa |
| 1 | bbbbbb |
| 2 | ccccccc |
| 2 | dddddd |
| 2 | eeeeee |
| 3 | ffffff |

and now I want to do a select that returns all values from every id in a list like:

1: aaaaa,bbbbbb
2: ccccccc,dddddd,eeeeee
3: ffffff

How can I do this?

View Replies !
Select Count From A List Of Digits ??
I'm using php to extract data from postgres and print to browser. I have data that was input through checkboxes on a form - each checkbox had a different value but got pushed into the same column. Code:

View Replies !
Select A List Sorted By Date
i am looking for way to get DATE() results properly
from my database sorted by MONTH and DAY
without YEAR.

example:
2007-06-23
2003-03-01
2005-07-27
2006-11-28
2007-12-01

today is 2007-04-25
<?
$query="SELECT * FROM domain_status
ORDER BY
(MONTH(date) < MONTH(NOW())),
MONTH(date) ASC,
DAY(date) ASC";
?>

the result is:
2007-04-20 <!-- this one is > 04-25 and therefor has be at the end of the row
2006-04-07 <!-- this one is > 04-25 and therefor has be at the end of the row
2007-06-30
2003-06-23 <-- this one must be on top of 06-30, cos its sooner.

View Replies !
List All Tables In Db Using SQL Select Command
I need to get a list of all tables in a MySQL database.

(I'm running 4.0.1) atm.

I need to get at the tablenames using a plain sql select statement. I can't use show table and i can't use api functions.It has to go through odbc and ado.net!

Schema information ought to be available somewhere, right? (Of course I can't scan the directories for files either!)

follow-up question: is there an ole_db driver for MySql?I could use its getSchemaTable function then.

View Replies !
SELECT A List Of Words With Commas
I have a column called fruit_type which contains text values like:

Row 1: apples, oranges, bananas
Row 2: bananas
Row 3: oranges, bananas
Row 4: apples
Row 5: NULL

I am trying to write an sql statement so that I get grouped/distinct results like:

apples
oranges
bananas

If I run the following query:

SELECT fruit_type
FROM fruits
WHERE fruit_type <> ''
ORDER BY fruit_type ASC

...I get:

apples
apples, oranges, bananas
bananas
oranges, bananas

View Replies !
SELECT Rows With Field Different From Previous Rows
I have a table (sens_samples) with mysqlerature sensor samples taken every 5 minutes. Rows are: id (INT), sensor_id (INT), timestamp (DATETIME), mysql(FLOAT) and over_mysql(BOOL).

I want to make a query to get ONLY the rows when over_mysql field changed from "previous" row value. I know that database rows are UNORDERED, but ORDER BY can "place" them in a given order.

My query may be "syntactically" something like: SELECT timestamp, mysql FROM sens_samples WHERE "PREV_ROW".over_mysql <> over_mysql AND sens_id = 1 ORDER BY id;

How can I get it using MySQL?

View Replies !
Select To Return A List Columm Without GROUP_CONCAT
I allready try something like this...

select name,(select ID from table where id = X.id)
from table X
group by name

-> return a columm with all "grouped" IDs
john, "12,12,1,2323,54"
marta, "1222,11,2"
josh, "69,87"

View Replies !
Select With Multiple Primary Keys Against List Of Values
I have created a method that automatically parses the metadata of a specified table and searches each field to effectively create a database search.

The way it currently stands, it only supports tables with a single PK. Basically it returns a string that can be appended to the WHERE clause in a SELECT.

i.e. "ID IN (1, 2, 3, 4)"

Basically the PK field name and a list of matching PKs from the search.

I realized though that this will break if I have a table with multiple primary keys.

An elegant solution for this eludes me, and that is what I am asking for input on.

Right now I can only think of returning something like :

"(ID = 1 AND SSN = '123121234')
OR
(ID = 2 AND SSN = '432434321')
OR ..."

This obviously would become a monster if many results were returned.

And if I did something like :

"ID IN (1, 2) AND SSN IN ('123121234', '432434321')"

This will either return false positives or nothing at all ...

Is there a better way for me to create this conditional?

View Replies !
Don't Select Rows That Match Both Columns But DO Select Rows That Don't Match Both
I suppose it is because it is 2:30 AM but I'm having a bit of trouble figuring out the SQL I need to write. I am usually pretty good at this. Here's what I'm having trouble with.

My app includes a Poll system built from scratch. Each question will run for one month. the month that the poll will run is kept in 2 columns in my table... runMonth and runYear.

What i'm having trouble doing is selecting the rows that don't match both the current runMonth and current runYear.

My Table...

id.............Question...........runMonth...........runYear
1..............QA...................1......................2007
2..............QB...................2......................2007
3..............QC...................3......................2007
4..............QD...................4......................2007 (current month and year)
5..............QE...................5......................2007
6..............QF...................6......................2007

I can simply get the question for the current month...



SELECT * FROM table WHERE runMonth = 4 AND runYear = 2007;
but if I try to get all others using


SELECT * FROM table WHERE runMonth != 4 AND runYear != 2007
I get an empty result set. As I should because there is nothing there that the runYear != 2007 doesn't knock out. The result set I am looking for is


id.............Question...........runMonth...........runYear
1..............QA...................1......................2007
2..............QB...................2......................2007
3..............QC...................3......................2007
*********************(remove runMonth4 and runYear 2007)
5..............QE...................5......................2007
6..............QF...................6......................2007

What am I missing?

View Replies !
Using A Field, Which Is A Comma Separated List, As The List In An IN Comparison Test.
The following query only reads the first character of a comma separated list stored in a field of the records being queried.

The varchar field in table d named "display" holds 1,4

The query " select * from d where 4 IN (display) " tests false.

If I change the field "display" to 4,1

Then the query tests true.

It is either testing only the first character, or is stopping at the comma.

I need this to test true if the value is anywhere in the list, what am I doing wrong here?

View Replies !
Full List Of MyTable21 And Some List Of MyTable22
data in myTable21

(id) country
(1) Canada
(2) France
(3) Egypt
(4) America

data in myTable22

(id) city name
(1) Montreol Jane
(2) Paris Mary
(3) Cairo Tom
(4) New York Jane
(4) Chicago Tom
I have data in myTables like the above.


The following code produces the following result. but I like to produce my target result.



code1

select myTable21.id, name, country, city
from myTable21
left join myTable22 on myTable21.id=myTable22.id

where
name='Tom'

result1

(3) Egypt Cairo
(4) America Chicago

target result1

(1) Canada
(2) France
(3) Egypt Cairo
(4) America Chicago



code2

select myTable21.id, name, country, city
from myTable21
left join myTable22 on myTable21.id=myTable22.id

where
name='Jane'

result2

(1) Canada Montreol
(4) America New York

target result2

(1) Canada Montreol
(2) France
(3) Egypt
(4) America Chicago




code3

select myTable21.id, name, country, city
from myTable21
left join myTable22 on myTable21.id=myTable22.id

where
name='Mary'

result3

(2) France Paris


target result2

(1) Canada
(2) France Paris
(3) Egypt
(4) America
How can I get the full list of myTable21 and selected values from myTable22?

View Replies !
SELECT With 1,000,000 ROWS
I have aproximately 1,000,000 rows and I would like to do some query. The
first one is to get the number of row so I do :

mysql> SELECT COUNT(*) FROM `Log`;
+----------+
| COUNT(*) |
+----------+
| 969129 |
+----------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(*) AS `Nb` FROM `Log` WHERE `ID` = 49;
+--------+
| Nb |
+--------+
| 969129 |
+--------+
1 row in set (1 min 20.99 sec)

But like you can see it, it take a long with the WHERE clause. I use Pentium
III at 650 Mhz with 48 Mb of ram. I think that the probleme come from the
computer but I'm not shure (I need more RAM ?).

View Replies !
Num Of Rows In SELECT
I am just wondering if it is possible in one query to select some rows using WHERE and LIMIT clausule, and get the number of rows I would get when i dont use LIMIT.

if I have
SELECT * FROM table WHERE column1='something' LIMIT 10, 15;
i know it is 15 rows selected. But i need to know how many rows are in:
SELECT * FROM table WHERE column1='something';

I know, there is a way.. just to do both SELECTs.. and retrieve data from the first one, and num of rows from the another one..
But I just dont want to make two SELECTs if there is maybe some solution how can i do it in one query.it for page with forum where i want to show users how many threads are in database, but at one page i need to show just 15 threads...

View Replies !
Select All Rows
I'm trying to figure out how to select all rows created during the current month. So, for instance, now I would want it to return ALL rows created during May. Next month, it should show every row created in June 2005. In my database, I have the field "date," where a date is stored in mm/dd/yy syntax, and I also have a "timestamp" field, which is created using PHP's time() function.

View Replies !
Select Rows With Max Value
Given a table like this:

CREATE TABLE IF NOT EXISTS `people` (
`name` varchar(10) NOT NULL,
`age` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `people`
--

INSERT INTO `people` (`name`, `age`) VALUES
('bob', 13),
('john', 25),
('mike', 25),
('steve', 8),
('sue', 13);


How would I select only the rows with the highest 'age' value?
In other words, because "john" and "mike" are the oldest, I want only their rows.

View Replies !
Select Only The First X Rows
Is i posible to select only the first X rows? Or row X to X?

ID want help me, it will be diffrent from one day to another...

Now it might be ID 1 to 3 but later it is ID 6 to 3 on one set and 0 to 3 on another

View Replies !
Select All Rows Except One...
This is a dumb question. These are my rows with three columns.

id | Firstname | Lastname |
----------------------------------------------------
1 | John | Smith |
2 | Jill | Smith |
3 | Joe | Smith |
4 | James | Smith |
5 | Jello | Smith |
6 | Joseph | Smith |
.
.
.
n | xxxxxxx | xxxxxxxxxx |

How would I select all rows except the last row without using PHP to manipulate the LIMIT keyword?

SELECT * FROM tbl ORDER BY id LIMIT 0, (SELECT COUNT(*) FROM tbl) - 1
course the above statement doesn't work... but you get the point.

View Replies !
Creating List Of People Not On List
I am using the following query to try to get a list of people not in a specific list. I can further restrict it by company name but I am getting duplicate entries if the person is listed on multiple lists. (It is further reduced by a clause to restrict by company, but that is not causing errors AFAIK)

SELECT people.`First Name`, people.`Last Name`, people.PersonID, Company
FROM people LEFT JOIN listtrack ON people.PersonID=listtrack.Person_ID
WHERE (listtrack.List_ID<>4 Or listtrack.List_ID Is Null)

If I remove the List_ID<>4 clause then I get people who are not on any list., but I want to be able to add one person to multiple lists, without running the risk of data duplication.

View Replies !
Select Duplicate Rows
In a table, i have records about phone number and stateID, sometimes there are rows that have the same phone number with different stateID (assume stateID has value from 1 to 50, or 100), I want to find out duplicate phone numbers with stateID value of 100 (those same phone numbers also contain stateID of value between 1 and 50). Can someone please tell me what would be the query for selecting this?

View Replies !
Select Specific Rows
I need to select several rows that have the ID 1,2,5,77,5,3,7,9
Is this possible to do in one query?

View Replies !
How To Select Rows Which Contains Certain String
How can I select rows which contains certain strings. Using "Like" clause we can do but its not giving exact results.

View Replies !
Select All Matching Rows
I need to look in table 1 and pick all those records not in table 2.I know that table 2 has 51000 records and table 1 has 65000. I want to see the 14000 in table 1 that doesn't have a match in table 2

View Replies !
Select Multiple Rows With The Same Id
So I have this table:

table_name

id_one ---- id_two
1 ---------- 1
1 ---------- 2
1 ---------- 3
2 ---------- 1
2 ---------- 3

I want to select all of the id_one rows where the id_two is '1' and '2'. The desired output is:

id_one
1
1

Later I might use SELECT DISTINCT to produce the following:

id_one
1

So far I have:

SELECT id_one FROM table_name WHERE id_two IN ('1','2')

But this selects all the id_one rows where id_two is '1' OR '2'. I want the rows where it is '1' AND '2'.

View Replies !
How Can I Select Duplicate Rows?
I need to select all the duplicate rows in a table. I need to display the rows selected, not just a count of the duplicate rows (which I do know how to do.) ....

View Replies !
Trying To Select Rows With Max Date
This is my query:

SELECT i_dest,i_rate, price_1, effective_from
FROM Rates r
ORDER BY i_dest;

I have multiple entries for each "i_dest". Every entry does have a unique i_rate (the younger the entry the higher the i_rate since it's the tables primary key with auto-inc). Also every entry does have a unique effective_from datetime value.

I would like to select all distinct i_dest definitions having either the highest i_rate value or the highest/youngest datetime in effective_from.

I have tried something like this:

SELECT i_dest,i_rate, price_1, effective_from
FROM Rates r
GROUP BY i_dest HAVING MAX(i_rate);

Unfortunately this does not work, i.e. it does not result in only the rows with the highest i_rate.

If I go like this:
SELECT i_dest,max(i_rate), price_1, effective_from
FROM Rates r
GROUP BY i_dest;

then I do see the highest i_rate BUT the price_1 and effective_from entries are those from other rows with a lower i_rate (and same i_dest obviously).

View Replies !
Select Rows On MAX(date)
My application inserts rows with a run_date - often all the other data will remain the same. I need to count only the rows with the latest run_date (and other WHERE clauses defined by the user).

Table looks like:

|rundate |vendor|users|vertical|
|2009-02-01|blah |100 |chemical|
|2009-02-02|blah |100 |chemical|

So my query needs to return '1' as only the latest run_date should be included.
I've played with MAX(run_date) but I don't know how to use it as part of a WHERE clause.

e.g. SELECT vendor, COUNT(*) FROM results WHERE vendor = 'blah' AND MAX(rundate);

View Replies !
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...

View Replies !
Select 5 Rows Per Column Value
ID | NAME | EMAIL | CITY |

How could i select 5 rows for each city value?
In other words, if there are rows containing St. Luis, NY, LA - I want to select 5 users from St L, 5 from NY and 5 from LA.

View Replies !
Select First X -groups- Of Rows
What I've got is 3 tables: news, category, newscategory. newscategory is just a linker table, so the relationship is like this:

[news.newsid] <--> [newscategory.newsid][newscategory.categoryid] <--> [category.categoryid]


One entry in 'news' can be attached to many different categories via 'newscategory'.

What I want to do is return the first X news posts from 'news', along with all the categories that each post belongs to. I can't figure out how to do this: using an INNER JOIN there will be multiple rows for each news post as there will be multiple categories associated with each post, (one row per category per post) but the LIMIT 0, X clause will apply to all the rows,

View Replies !
Select The First Letter Of Each Rows In A Db
I want to be able to select only the first letter of each row in my table.
I want to select only DISTINCT row so i would have as a result, an array of letters. For example, if i have 25 rows starting with the letter 'A', well 'A' would come out only once.

View Replies !
SELECT Results After X Rows
I am trying to run a league creation script using php and mysql. I was thinking that i could do it by getting every user into one column and then pair them off by starting from the second result found and place that with the first user in the first fixture row. For the next fixtures i would place the 3rd result found in a row with the initial users.

This way i make sure they dont play each other twice and each fixture created in unique.

Is their a mysql function to do a select query but dont have it start outputting the results until it reaches a certain row from the results? I will also need it to go back to the first result found once it reaches the end of the results.

View Replies !
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.

View Replies !
Is That Possible To Select Range Of Rows?
I use simple query right now to select rows from database:

SELECT * FROM cities WHERE country = '$country' ORDER BY city

But what if I need to select not all rows (from 1st to 800th, for example), but only rows from 70th to 140th? Is that possible to select this range with MySQL query?

View Replies !
SELECT And Exclude Rows
SELECT * FROM
myTable
ORDER BY DATE DESC
The result of this query is:

17/08/2008
17:11:38
CERTALDO
BOSCO

17/08/2008
16:58:01
CERTALDO
BOSCO

17/08/2008
15:05:27
CERTALDO
BOSCO

17/08/2008
14:48:31
CERTALDO
BOSCO

17/08/2008
14:43:38
CERTALDO
BOSCO

17/08/2008
09:43:56
SUBBIANO
CAPOLONA

17/08/2008
00:16:13
ROSIA
DOCCIO...

View Replies !
Select List Table Name Beside SHOW TABLE
is there any way to select list of table name beside using SHOW TABLE syntax

by using SELECT syntax

such as SELECT bla bla bla

View Replies !
Select With Dummy Rows When Grouping?
If I select from a table and, for example, group by the month or day
to determine how much activity there is day to day or month to month,
it will only return months and days with a record and leave out any
month or day without any records making it apear at a glance that
every day or month has activity which forces me or whoever to have to
look at the date column and actively look for spots where a day or
more elapses without a single row in order to determine when nothing
has happened.

Is there any select method for grouping on something
like a month and to have it output a dummy row for missing days or
months without having to write a program that makes an individual
select for each day?

View Replies !
Select With Dummy Rows When Grouping
If I select from a table and, for example, group by the month or day
to determine how much activity there is day to day or month to month,
it will only return months and days with a record and leave out any
month or day without any records making it apear at a glance that
every day or month has activity which forces me or whoever to have to
look at the date column and actively look for spots where a day or
more elapses without a single row in order to determine when nothing
has happened.

Is there any select method for grouping on something
like a month and to have it output a dummy row for missing days or
months without having to write a program that makes an individual
select for each day.

View Replies !
Select Distinct With Multiple Rows
SELECT distinct name, id FROM `raffaello_ties` WHERE `advertisercategory` like "Cufflinks and Tie Clips" order by name limit 0, 200
it works, but it doesn't select distinct names. if I changed it to just "distinct name" (and leave out id) it works fine.
how are you supposed to use select distinct with multiple rows?

View Replies !
Select Rows For Date Range
i want to select records between 11 dec 2004 to 25 dec 2004 plz tell me qry.

View Replies !
The SELECT Would Examine More Than MAX_JOIN_SIZE Rows
I am getting this error. could someone tell me what it means?

The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay

View Replies !
Select Rows Only Created LAST MONTH
i want to run this below command, but only look at records from the previous month and where ACTIVE = 0

MYsql>
SELECT user,ROUND(AVG(overalldone), 1) AS average FROM data GROUP BY user ORDER BY average DESC;


View Replies !
Simple Select Returning More Than One Rows
I would like to ask if it's possible to do a select 1,2,3 and to be returned 3 rows and 1 column with values 1 for the first row,2 for the second etc. select 1,2,3 returns me a row with 3 columns.

View Replies !

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