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




Sort By 2 Colums As 1


I have 2 tables lets say called: files and notes
files has 2 fileds filname and date_added
notes has 2 fields note subject and date_added

if files had 2 records:
1) file1.pdf : 2007-06-14
2) file2.pdf : 2007-06-17

if files had 2 records:
1) great day out : 2007-06-15
2) why me? : 2007-06-18

i want to sort by the date in both fields but as if they were in 1 fields so output would be
2007-06-14
2007-06-15
2007-06-16
2007-06-17
and not
2007-06-14
2007-06-17
2007-06-15
2007-06-18




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Specify A Value For At Least One Of The Colums
i have created a database for a form to hold peoples details who come to my marquee site. i have done most of the entrys as varchar and set null to not null and dont know what to put int he default so left it blank! i have connected to teh db in dreamweaver thts all fine but when i try to insert record i get please specify a value for at least one column.

Possible To Shift And Splice Colums?
In MYSQL is it possible to shift and splice colums?
say I have a table w/fields: name | tele_num | age
and I get all the addresses later - address initally
stored in a txt type file with 1 rec /line.
I now want: name | address | tel_num | age
Can I do it this? if not can I do:
name | tele_num | age | address ?

Just need the tools cmds to use and the "flow"
you don't have give the actual SQL unless you want.

Show Colums" With A Where
I would need to know if there is a way to filter a Show Columns. The thing is I want to let my customers modify all the fields except the primary key. But since I may not always be the DBA I cannot create the field with the same name. So I need to determine if it's the primary key and if so, I will not show it.
Also I cannot work with views because I will not always be the DBA and also because it would require to create as much views as there will be tables.
So is there a way to inlcude a Where in the statement? If not, is there a command to determine if the field is the primary key?

Query To Display The Rows As Colums Is Not Working!!
I want a select query to get two columns. but i need to get these columns one below the other that is consider that i have a table student in that i have 2 columns name mark.
Now i want the result as

Name Raj Rina Tina
Marks 80 90 70

I tried the --vertical option of mysql and G option in the query.

for example when i tried

select *from studentsG

it displayed

*********** 1. row ***********
name: Raj
marks : 80
********** 2. row ************
name: Rina
marks : 90
********** 3. row ************
name: Tina
marks : 70

but i want to display

Name Raj Rina Tina
Marks 80 90 70

Sort With Limit But Sort ALL Results.
I have a query that limits by 50 results at a time and I also have an order on a int field. The issue I'm having is it's only ordering by the 50 it returns, how can I have it order by the entire results set and then give me back only 50 results?

Sort With Limit But Sort ALL Results.
I have a query that limits by 50 results at a time and I also have an order on a int field. The issue I'm having is it's only ordering by the 50 it returns, how can I have it order by the entire results set and then give me back only 50 results?

Sort
I have a table "users" with fields like:
first_name, last_name, photo_name, date

"photo_name" values are either NULL or
something like
"2_50_tim45.jpg"
"3_50_franky70.jpg"
"4_50_john_long.jpg"

Meaning not all users submitted their photos and those I would like to show at the end
of my HTML table.How do I make a query so that I would get resultset

that would show first users that have "photo_name" and then they would be sorted by
date.

SELECT * FROM users ...

Sort
I would like to know if it is possible to order the results by the quotient of to numbers.For exampel:

$sarray=mysql_query("SELECT * FROM table ORDER BY (rating/votes) DESC");
anyone have a clue how to get it to work?

Keep Sort
The website is an ecommerce site that provides customers with the ability to "browse" the product line. In other words they can move from one item to the next until they get to the last item.
The question is: How can I insert a new item(row) and position it somewhere in the middle of the table? Currently, the table is sorted by the primary key which is numbered 1, 2, 3, etc. (whole numbers). Obviously I can't assign the same primary key to two items. My only thought is to use decimals in the primary key instead of whole numbers. So a row entered between 1 and 2 would be 1.1, 1.2, etc.
Does this make sense? Is there an easier way?

Sort Certain Value
I am displaying results from a table. One row, "position" contains values such as "President", "Vice President", or "None" (many of these).
Is there a way to order the results, alphabetically, by the "position" column, but sort any rows with a position of "None" to the bottom?

Sort Something
sort a list by name and birthplace but I don't really know how to do that. Can anyone give me an example?

Sql Sort
Code:
$sqlquery = "SELECT * FROM $ssl_table WHERE user='$login' ORDER BY date DESC, ticket_host DESC";

I'm using this query and want to sort a list by date and then by Alphabetical order for the teicket_host.

Yet it out puts like this:
2007-01-19 BH
2007-01-18 HM
2007-01-18 HM
2007-01-18 BH

The date is good but the 2nd Sort is not doing Alphabetically. I want it to go:
2007-01-19 BH
2007-01-18 BH
2007-01-18 HM
2007-01-18 HM

SORT BY
I have a very large table that is always sorted by the primary key when I SELECT data from it. Actually, the very purpose of the data being in a database is so that it can be sorted like that. I was wondering, however, if there's some way to use the WHERE clause in SELECT (or a seperate token) to actually give me, say, the 10000th entry if it were to be sorted. Something along the lines of:
SELECT name FROM data WHERE %place% = 10000 SORT BY income DESC
So basically if I had a database of names and their incomes in no particular order, I would need to find the name that has the 10000th highest income.

Automatic Sort
Is there a way to automatically sort "inserts" according to date in mysql? I have searched high and low for something like this in mysql. I know that it can be done in MS sql but cant find it for mysql.

Sort By Date
Sorry i want to show the records if the 'maxdate' is equal or greater than curdate....

No Sort Order?
I have a SELECT statement such as:

SELECT category, title, pubdate FROM ds WHERE category = 3 OR category = 5 OR category = 4 OR category = 101 OR category = 7

I want the result set to return the results in the order that I have queried above (ie: 3,5,4,101,7) but MySQL seems to sort the category so I get the results as (3,4,5,7,101).

Other than splitting into 5 SELECT statements, is there any way I can use a query to say "DO NOT SORT"??

Sort Problem
I'm new to mysql and ran into this sort problem.

Say I have these entries and this is the sort order using char data type:

C100
C1000
C150
C200

I need the sort order to be this:

C100
C150
C200
C1000

What data type do I use?

Sort Aborted
I am getting Error 1028 Sort Aborted, is there any information available that may help me determine the cause of this error.

How To Sort In Mysql By Own Needs
filename: p1.pdf, p2.pdf, p3.pdf...pN.pdf in database column. select filename from filename from table order by filename -- the returned result won't be in the filename order.

But If I change the filename to p001.pdf, p002.pdf, etc. It will work fine. Is there any way to make it work in the 1st scenario? i.e. sort in filename order.

Sort With A Limit
What I need to do is display results that are sorted based on user preference. These results need to be paged to display 25 results per page. Currently I'm using a simple sort and limit. However, as many of you smart folks know, MySQL only sorts the values it finds within the limits as opposed to sorting the whole table and then limiting results.

SORT BY With Condition?
is there a way to do sorting depence of some condtion directly in the MySQL query?
for example, I have this query:

SELECT cat_id, cat_name, cat_date, cat_parent
FROM categories
ORDER BY cat_name ASC
but I'd like change sorting if cat_parent = 23 for example.
so, is there a way use something like:
SELECT cat_id, cat_name, cat_date
FROM categories
ORDER BY ((IF cat_parent = 23) THEN cat_date ELSE cat_name) ASC

I dont know MySQL at all, so this is just an example of condition idea that I'd like to use.

Sort A List
how can I sort my database by the age of the people that I have in the database and the place they live.

Natural Sort
how is possible sort rows in table like php function natsort - http://php.net/manual/en/function.natsort.php Values in my table.

- "35 - somethig"
- "51 - somethig"
- "06 - somethig"
- "01 - somethig"
- "02 - somethig"
- "08 - somethig"
- "ZC"
- "BA"
- "AA"

I need this order
- "AA"
- "BA"
- "ZC"
- "01 - somethig"
- "02 - somethig"
- "06 - somethig"
- "08 - somethig"
- "35 - somethig"
- "51 - somethig"

Not Sure To Use Filer Or Sort
I have fields Date, Exporter, Importer, Waybill, Agent, Destination in my table.
I wish to sort or filter by Date and Agent only. but it must give all the info regarding that criteria. I've tried GROUP BY but it only consolidates the info. My Date column is date and not varchar. My date column is yyyy-mm-dd.

Sort NULL Last
I have a mysql query, "SELECT * FROM task ORDER BY duedate ASC", where
"duedate" is a unix_timestamp and can be NULL. I want any NULL results
to be at the end of the list, how might I do this?

Array And Sort
I have products that belong to certain categories. I want to array the product (mysql_fetch_array), and ORDER BY the Category they belong to. However I dont want the category to array each time.

I want
CATEGORY ONE | CATEGORY 2
product one | product one
product two | product two

The code i am using is --

$query ="SELECT category.cat_id, category.catname, inventory.cat_id, inventory.product, FROM category INNER JOIN inventory ON category.cat_id = inventory.cat_id ORDER BY catname ASC";
.................
while($row = mysql_fetch_array($result)){

echo "<tr><td>";
echo $row['catname'];
echo "</td><td>";
echo $row['product']; ETC

How can i array the products with out the Category, but have category as a heading??? where the arrayed products will go under.

Sort Aborted
I am getting the error "Sort Aborted" when executing the query "SELECT object2, userid from users1 ORDER BY object2;"

Sort Asc W/ Most Recent
I want to display the five most recent rows in my table (there is a timestamp), but sorted in ascending order.

the problem is that when i call

SELECT * FROM spam ORDER BY time ASC LIMIT 5

it shows the first five entries in ascending order, but i want the last
five.

needless to say, it works fine with descending order..

Group And Then Sort
Hi all i have a query that i did that is working fine as in so far of gathering the data that i am after , it is the following.

$result = $DB->query( "SELECT name, AVG(speed), COUNT(*) FROM readings group BY `$srtby` DESC LIMIT $maxshow");

what i am trying to also do is have the results sorted by speed , is it possible to both group by as well as sort by , i have tried numorous combinations but cannot seem to get it to work.

SQL Sort (Order By)
I have sql statement below ,


SELECT
serial_no,host_name,chasis_model,chasis_flash_size ,chasis_dram_size,
country,city,building,other,chasis_sw_version,stat us,chasis_eos,chasis_eol,chasis_user_field_1,chasi s_user_field_2,chasis_user_field_3
FROM tbl_chassis ORDER BY country = '', country


However , my user would like to sort by country,city,building and other
columns .
Anybody have ideas how to do that ? I do order by
country,city,building,other gave me the result which i not expected.

For example below data before sort

Country City Building Other
Thailand Bangkok 208 Wireless RD
Thailand Bangkok 208 Wireless RD
Thailand Bangkok 208 Wireless RD
Thailand Bangkok 208 Wireless RD
Thailand Bangkok 83 Aber rd
Thailand Bangkok
Thailand Bangkok 12 Godieon Rd
Thailand Bangkok 900 Telepark

After sort

Country City Building Other
Thailand Bangkok 83 Aber rd
Thailand Bangkok 12 Godieon Rd
Thailand Bangkok 900 Telepark
Thailand Bangkok 208 Wireless RD
Thailand Bangkok 208 Wireless RD
Thailand Bangkok 208 Wireless RD
Thailand Bangkok 208 Wireless RD
Thailand Bangkok

Predicting SORT BY
I have a very large table that is always sorted by the primary key when I SELECT data from it. Actually, the very purpose of the data being in a database is so that it can be sorted like that. I was wondering, however, if there's some way to use the WHERE clause in SELECT (or a seperate token) to actually give me, say, the 10000th entry -if it were to be sorted-. Something along the lines of:
SELECT name FROM data WHERE %place% = 10000 SORT BY income DESC.

Sort List By Day
ive got a list of days i.e. monday, wednesday, friday etc. in random order.
The problem is i want to sort the list by the day of the week, so monday first then tuesday, wednesday etc. is it possible to do this?

Sort Of Like Distinct
Is there a way to retrieve a set number of duplicate results?
For example, I have a calendar application and I want to retrieve only 4 results per day.
The data is like this:

Woo, 6
Yes, 6
Foo, 6
Bar, 6
Yay, 6

where those 5 entries are from the 6th of the month, so basically I want to limit each distinct date to 4 results.

Sort By Relevance
I am doing a nested loop using MySQL database, basicly I have

loop1
- city, state, city1, city2, city3, state1, state2, state3

   loop2
    - city, state

  movenext loop2
movenext loop3

Lets say loop1 has a city= 'Riverside', state='CA'

on loop two I would like to show all matches to Riverside first or matches to the other cities first. Cities are more important than states but states do take a factor.Right now its working but it throws the important matches in the middle of the 10 results, because CA is part of the display criteria.

Sort By Date
I just have a question thats probly simple for you SQL pros out there but im trying to sort my Table in vb6 by date i tried everything i could think of to put it in the WHERE of my SQL statment but i cant get it to work, Also I would like to be able to sort it in a date range like Between DAte1 and Date2 Thanks in advance everyone Happy programming

Sort By Date
I need to select all records and sort them by date (with php and mysql) like > "SELECT * from table SORT BY date"

the thing is the date is not a unix timestamp in database, it is in form "dd-mm-yyyy" e.g. "20-12-2005".

How can I do that ?

Mysql Won't Sort
Last in, first to appear is the desire. Yet when I call on the database via php, I get post for May 9, May 8, etc, and after that May 24, May 23, May 21. Something’s wrong.

$query = "SELECT  PostID, CONCAT(FName, ' ', SName) AS Name, About, Date_Format(DoA, '%b %e') As DoA FROM Post ORDER BY DoA DESC";

Sort, Limit
I am trying to do a query like:

(SELECT * FROM table1 ORDER BY frequency DESC LIMIT 50)
ORDER BY name;

Where the top 50 frequency values are then sorted by name. When I try
this, it displays each equal frequency value sub sorted by name (so all
freq = 50 are shown a-z, then all freq=40 shpwn a-z etc), rather than
showing the top 50 frequencies sorted by name which is what I want to
achieve.

ORDER BY Sort
When a number is stored as a character string, in what order does ORDER BY sort? ASCII-betical? Or numeric?
I can't believe I've spent half an unsuccessful hour trying to Google an answer to such a simple question!
I'm curious because I want to store a bunch of numbers, some integers and some decimals, and want to know if it makes any difference whether I store them all as decimals or as characters

Sort By Relevance
Im building a very simple search engine, it searches a number of database tables.
At the moment Im using Union to do a number of query and join them into a single set of results.Is there anyway I could implement a very simple sort by relevance kind of thing?

Sort By First Letter
I would like to be able to sort by the first letter of a field.
I have a problem where I have business's in a list and would like it to be alphabetically sorted.However, the listings that are priority (paid listings are '1', normal are '0') listings, I would like these at the top of each character section eg, A, B, C etc..

Sort Children Under Parents
I am sure this has been asked many times, and I bet that it is super easy, but for some reason I am not able to wrap my head around it right now. I have a table with an id and a parent_id. I have a report that lists all of them onto a page the admins can look at. I want to have all the rows with a parent_id to fall under their parent's id. How can I pull this off?

Btw if there is no parent then parent_id is 0.

ORDER BY Doesn't Sort As Expected
Would anyone be able to look at the following statement and tell me why ORDER BY is not behaving as expected.
SELECT RTeamName, SUM( RGamePld ) , SUM( RGameWon ) , SUM( RGameLost ) , SUM( RGameDraw ) , SUM( DLegFor ) , SUM( DLegAgainst ) , SUM( RPointsSum )
FROM LeagueTable
WHERE RDivision = 'A'
GROUP BY RTeamName
ORDER BY RPointsSum DESC
LIMIT 0 , 30
All of the Database fields are correctly spelt and the database has two records in for each team. The results displaying in the SUM() fields is correctly calculated but is not sorting by RPointsSum. The team with the most points is currenty halfway down the table.
Any suggestions why this isn't sorting so that the team with two points is at the top of the table?
I can send screen shots if that helps. Cheers



Sort By Formatted Date
Hey guys and gals of sitepoint. I am using a select statement to pull some data sorted by date, but I am also wanting to format the way the date looks when displayed on screen. As you can see by my select statement below this is not the problem; my problem is the items are not being displayed by their chronological date correctly (i.e. out of order). Any pointers on how to correct this?
mysql_query("select id, name, body, date_format(date, "%b %d '%y at %h:%i %p") as date from pages where cat_id=&#393;' order by date desc")

How Do I Sort Data Fro A Bad Form Into Something Useful?
I made a bad form with a form creation app in a hurry. Now I have a table that is nearly useless.

The form was meant to record teams for an upcoming volleyball tournament. I provided inputs for the school name, mascot, student, etc. The form app allows me to copy form elements, so I did.

The table now shows about 120 student, and grade, position, sorted by a form id (one for each team) but they are sorted by the record id.

Instead of:

Team | Student | Grade | Position | etc.....

I have:

record | name | value | etc...

I have tried some queries that just basically remove some superfluous column and GROUP BY record (that is the form id, so the third team to register has "3" under record.

Can I salvage this data by a clever query or am I looking at making a page via php to display the results?

Sample Data:

student name1 Curtis Geurts
student name1Tom Glasbergen
student name1Bill Lammers
student name1Marc Brouwer
student name1Kurt fledderus
student name1Nate Brink
student name1James Brouwer
student name1Scott Denbak
student name1Dave Stares
grade12
grade12
grade11
grade11
grade11
grade11
grade11
grade12
Player positionpower
Player positionsetter
Player positionmiddle
Player positionmiddle
Player positionpower
Player positionoffside
Player positionsetter
Player positionsetter

Sort By 2 Fields Unless One Field = 0
Quick recap - I know very little about databases. I'm trying to produce a query for a MySQL table.

The table has 3 columns of interest:
itemid - a unique integer representing this item
lastcommentid - a unique integer which is the unique id of a row in another table
itemname - free text name

I want to select all the items in this table, ordered by the following logic:

Quote:

- If the lastcommentid is not integer 0, order the results ascending by lastcommentid (lowest lastcommentid first)

- However, if the lastcommentid is integer 0, order the results ascending by itemid

- Regardless of the above 2 points, only return items with an itemid higher than N.

When done correctly this should return records ordered by their last activity, because either:

A comment was made on the item in which case its lastcommentid will be greater than other items' lastcommentid,

or,

No comment was made on the item but the itemid field is greater because the item was added after other items.

With Rollup - Sort Order
PHP

SELECT  B.BatchID,  J.JobID,  P.Project,  J.JobNumber,  P.ShipLocation,  J.JobType,  P.Country,  JR.ReleaseName,  SUM(B.Price) AS TotalPrice,  JR.JobReleaseID,  JR.TargetProductionDate,  JR.ATF,  JR.Reviewed,  JR.ProductionStatusID,  JR.ToShop AS TS,  S.FirstName AS SalesmanFirstName,  S.LastName AS SalesmanLastName,  S.Nickname AS SalesmanNickname,  C.AccountStatus,  C.Company AS Customer,  C.Nickname,  B.TargetDate,  B.ExchangeRate,  P.JobClassificationID,  C.CompanyID,  P.ProjectID FROM  Project P,  Job J,  JobRelease JR,  Batch B,  Company C LEFT JOIN  User S ON  S.UserID = P.Salesman_UserID WHERE  J.ProjectID = P.ProjectID AND   JR.ProductionStatusID != 4 AND   JR.JobID = J.JobID AND   JR.ProductionLocationID = '$SessionData[ProductionLocationID]' AND   P.Customer_CompanyID = C.CompanyID AND   J.JobID = B.JobID AND   JR.JobReleaseID = B.JobReleaseID GROUP BY  C.CompanyID,  J.JobID,  B.BatchID WITH ROLLUP

I want to organize this report to show the highest "ROLL UP" tally of TotalPrice, is that possible...

I need some genius help and fast, if possible, I am trying to get something done for our guys first thing tomorrow.

Sort On Multiple Unions
I have multiple union statements and I want to do a sort on them all. If I add the "sort by" statement to each particular statement will this do the trick or how is it possible to do a global sort of the retuned values?

Sort List By First Letter Of Last Name
I am trying to sort a member list by the first letter of a members last name. To do so, I have a link for each letter of the alphabet as follows:

<a href='members/users.php?action=Directory&sort=letter&letter=A'>A</a>

Then, I have a conditional statement which I use to choose the correct mysql_query:

if($sort == "letter"){
$result = mysql_query("SELECT * FROM ".$prefix."_users ORDER BY lname ASC LIMIT $nexlimit,$users_per_page WHERE lname LIKE '".$letter."%' ");
};

This query works if I remove the where statement. However, I cannot figure out why I receive an invalid argument statement when clicking on one of the letters to sort the list.


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