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.





ORDER BY WHERE + Include Rest Of Table Or ORDER? Possible?


I need to create some SQL that when run returns all the rows which a column is equal to number that has been specified, but then the query needs to return the rest of the rows in the table. How could this be done? is it even possible? Is their order syntax that could do this better?




View Complete Forum Thread with Replies

Related Forum Messages:
Re-order The Natural Order Of All Of All The Rows Of A Table
Basically I want to re-order the rows of my entire database. It has many thousands of rows, and people are constantly running the same query against it. The problem is its quite slow (using a shared host).

I know you can use an sql query to order by column, however I need to re-order twice and it really seems to be slow due to this.

Since the query is always the same, if the rows were already ordered in the database , then the ordering query wouldn’t need to be done.

Is there an easy way to do this, without deleting each and every row, then inserting them again?

basically in the database I have:

The natural order when you do a select * from this table (without using an order by query):
________________________
|cola |col.. |coln |
|dataA |dataB |dataC |
|dataX |dataY |dataZ |
|datal |datam |datan |

(obviously a lot bigger than this) and I want reorder the entire table , eg

The natural order when you do a select * from this table:
________________________
|cola |col.. |coln |
|dataA |dataB |dataC |
|datal |datam |datan |
|dataX |dataY |dataZ |

So is there an easy way to do this, am I just being dumb?
or do I need to delete the entire table and insert the rows one at a time in order?

View Replies !
Multiple ORDER & SUB ORDER On The Same MySQL Table
I am trying to do multiple ORDERS or SUB ORDERS on the same MySQL table, and I'm loosing my mind trying to fathom the logic and SQL statement to use, I'm no MySQL genius! more a newbie.

*** SEE ATTACHED IMAGE PLEASE

I have tried all sorts of SQL statements, e.g:

SELECT * FROM categories GROUP BY parent ORDER BY order, parent DESC

Nothing seems to work.

I think my only solution is to do a bubble-sort after putting the whole table in a PHP ARRAY ?

I'd also like the menu to act like the + pop-open sub-menu boxes on the Forum left column menu.

View Replies !
Speed Up Order Table Table-name Order By Col-name For Large Table?
I have a table with 2 column: id and name. Column name is of type varchar(100).
The table has about 0.1 billion rows, taking 11G disk space.

Now what I want to do is alter the table by the name column. I ran the command: "order table table-name order by name"

1).Firstly, it create tmp table,which takes 19G disk space.

2).After that,the 19G space seems to be released(I see the free disk space increase by "df").

3).Then I see that in the mysql directory, the size of the mysql file #sql-14f7-2.MYD" increases 2M every time, but very slow. I guess this mysql file is the new table after order. But how can it be so slow? It only increase 2M every 2 minutes or so, which would takes weeks to finish the command.

So could any one tell me how can I speed up this command? Are there any variables I can adjust to make this faster?

View Replies !
How To ORDER BY DESC Properly. It Makes 150 Before 50 If ASC Order!?
I have this list:
50
150
200
250
300
350
400
450
500

If I order it by ASC order then mysql results this:
150
200
250
300
350
400
450
50
500

What the hell ?? How do I order it properly?

View Replies !
Order Then Order Again But From Colums Of Different Tables
I'm a noob to sql and I've been using a query thats worked really well for me for some time, but now I need to optimise it a little further and things seem to be coming un-done

its used for a search query: .....

View Replies !
How To ORDER BY The Order Requested In The Query?
Here's my query:

SELECT * FROM myTable WHERE id=14 OR id=3 OR id=8

Simple stuff, I know. The result of the query is three rows that are all sorted by their 'id' in ascending order. I don't want this. What I want returned are rows sorted by the order in which I requested them. I need the query to return row #14, #3 and then #8 in that order.

View Replies !
How Does MySQL Order Records With No ORDER BY?
If you don't specify an ORDER BY clause, how does MySQL order the records? Is it just the order in which they found in the database?

View Replies !
Order By Field From Other Table
("SELECT * from `offers` WHERE `status` = 'On' ORDER BY `pay_value` ASC"); 

I need to pull the "pay_value" from 2 different tables and then order it by that only.

The first table is called `offers` and the field I'm referencing is `pay_value` type decimal(10,2) and the second table is called `exceptions` with a `pay_value` type decimal(10,2).

What I'm doing is showing a list of ads with the amount of money that each ad pays per lead/sale. Some of our clients have been given increased payouts. Well, when they go to sort all of the ads in the system via the 'Pay Value' I can't make it show the increased payouts from the `exceptions` table while at the same time, being in correct order with the other `pay_value`'s from the `offers` table.

I've tried the following:

PHP Code:.....

View Replies !
Reorder Table Order
I've set up my MYSQL database and now I'm pulling data from the table along with field name of each field. I set things up in teh wrong order though so I need to reorder the table fields so that all I have to do is pull the data straight out instead of reorganize teh array after I've pulled it.

View Replies !
Order Table On Primary Key
I have searched for a while but cannot uncover the answer. I have a database, and for each table I want to know which field is the primary key (if any) and then sort the table on that field. I'm sure there must be a simple way to do it.

View Replies !
Order Table Backwords
How can i order table backwords?

View Replies !
Order By Value In Another Table Column
myTable1

(n) city
(1) Tokyo
(2) New York
(4) Chicago
(5) Peking
(6) Nagoya
(7) Paris

myTable2

(n) cate
(2) 1
(6) 5
(6) 9
(7) 4
I have data above in myTables.
I like to produce myTable1 records ordering by myTable2 cate column.

The following is one of my trials.

trial code

select myTable1.n,city
from myTable1
join myTable2 on myTable2.n=myTable1.n

where
myTable2.n is NULL
or
myTable2.n=myTable1.n
or
myTable2.n<>myTable1.n

order by myTable2.cate, myTable1.n

trial result

(2) New York
(7) Paris
(6) Nagoya
(6) Nagoya
The following is my target result.

target result

(2) New York
(7) Paris
(6) Nagoya
(1) Tokyo
(4) Chicago
(5) Peking

View Replies !
ALTER TABLE `table` ORDER BY `column_a` DESC
I try to get better performance by implementing this:

http://dev.mysql.com/doc/mysql/en/alter-table.html

"ORDER BY allows you to create the new table with the rows in a
specific order. Note that the table does not remain in this order after
inserts and deletes. This option is mainly useful when you know that
you are mostly going to query the rows in a certain order; by using
this option after big changes to the table, you might be able to get
higher performance. In some cases, it might make sorting easier for
MySQL if the table is in order by the column that you want to order it
by later."

I run this SQL query on one of the table:

View Replies !
Derived Table With GROUP BY And ORDER BY
I am trying to get the following:

"pull the last, oh, 1000 topics, and rank that population by board posted-to and comments"

Here is the query as written for MSSQL:

View Replies !
Mysql Dump Table Order
How does mysql order the tables in the file that it creates? Is is it by the order the tables were created, by alphabetic order? can I specify an order by giving the table names in the command line?

View Replies !
ORDER BY W/ HEAP Table Type
I am creating an online application that lists the last 50 users that loaded a page.

I used a InnoDB table type for storing most information (which rarely changes), but was thinking of moving the UPDATE and SELECT function that tracks who last clicked something to a HEAP table for speed.

I think I would be OK with the UPDATE to a HEAP table, but I have read that ORDER BY cannot be used on HEAP indexes. But, do I have to use an Index?

Can I make a SELECT like this on a HEAP table that has only two columns (login and datenow)?

$queryonlineusers="SELECT login FROM mmih_users ORDER BY datenow DESC LIMIT 50";

View Replies !
Creating An Order Form - New Table For Each One?
I'm trying to create a simple database using mySQL which will be used to create various web based order forms, these forms will be used multiple times.

The first table is for the item and is stuctured:
-------------
|Item |
|-------------|
|Description |
|Part No. |
|Article No. |
|No. Required |
-------------

The order options form is structured:

-------------
|Order Options|
|-------------|
|System Name |
|PPNo |
|Item |
|Item |
|Item...etc |
-------------

Each order options form can have any number of items within it.

View Replies !
How ORDER A SELECT BY Weight Value FROM Another Table?
SELECT id, title FROM table1 where id IN (SELECT id FROM table2 where parent_id = $par);

What I need is to ORDER this output BY a weight value from a 3rd table:

SELECT id, weight FROM idAttributes where id IN (SELECT id FROM table2 where parent_id = $par);

Sure, both table rows are identified by the id, so both selects will return the same number of entries.

What's the trick to achive this? I don't want to use perl for this, because I believe MySQL could do this in some manner.

View Replies !
How To Order By Three Names In Foreign Table?
I need to create a paged list of items which is sorted by three fields which aren't even in the Items table. Meaning, in the same query, I need to perform three lookups to obtain the category name(s) assigned to the items. These are the tables -- in brief (note that "id" columns are autonumber and `cat_level` is an enumerator):

Items || item_id | item_code | item_name |
ItemCats || ic_item | ic_cat |
Categories || cat_id | cat_level | cat_name | cat_image | cat_desc |

The problem I'm having is that when I use something like the following query:

Select c1.cat_name as cat1_name, c2.cat_name as cat2_name, c3.cat_name as cat3_name, `item_code`, `item_name`, `item_id` From `Items`
Join `ItemCats` as ic1 On item_id = ic1.ic_item
Join `Categories` as c1 On c1.cat_level = '1st-level' and ic1.ic_cat = c1.cat_id
Join `ItemCats` as ic2 On item_id = ic2.ic_item
Join `Categories` as c2 On c2.cat_level = '2nd-level' and ic2.ic_cat = c2.cat_id
Join `ItemCats` as ic3 On item_id = ic3.ic_item
Join `Categories` as c3 On c3.cat_level = '3rd-level' and ic3.ic_cat = c3.cat_id
Order by cat1_name, cat2_name, cat3_name, `item_code`, `item_name`, `item_id`
Limit {$offset}, 2147483647;

Only those items which have all three category levels assigned to them are listed. I know this is because I'm using inner joins. However, if I change any of them to left joins, I begin to get duplicate items listed. Nevertheless, adding the "distinct" keyword doesn't solve it either because the duplicate items will have different category names at their different levels -- thus, the rows are already distinct.

View Replies !
Order By Highest Value Among Columns In The Same Table
I have a PHP MySql web based system where different people are supposed to rate an artist performance. To accomplish this task, each of these five judges should enter a value (for example: 5) in one field. So i ended up with a table with five columns, labeled "judge1", judge2", and so on. Code:

View Replies !
Order Of Fields In InnoDb Table
During my extensive reading a couple of weeks ago,I read that MySQL tables should have their fields in a specific order.All the foreign keys should be first followed by the 'hard data' fields.

explain if this is, in fact,necessary and, if so, why.I can't recall where I read it or I would go back there again.

said it should be like this:

unique_id | business_id | address_id | first_name | last_name |
00001 | 00005 |00003 | Joe | Soap |

View Replies !
Order By Based On Results From Another Table
I have a query that , and i need to order the result based on wheter or not the ID of my main table appears on another table, somewhat like this:

SELECT A.id AS Id, A.nome AS Nome
FROM main_table A
JOIN joined_table JT ON JT.id = A.id_cat
ORDER BY ("first whoever have a row in" another_table AT)

another_table stores the image paths related to main_table , i need to show all query results from main_table even if they don't have a image (row in another_table), but i need to show whoever have a image (a row in another_table) first...

I've tryied to join with another_table and even to use sobqueryes in ORDER B... but so far i got no results. it's even worst because this query is a monter with multiple lines (the sample is simplyfied...)

View Replies !
Order By - Order Of Precedence?
I know how to use the order by, but wondered if there is an order of precedence in using it.

Facts: hcounty is a county that someone puts in a home county in which they live. In the comments they are also allowed to put text, that might contain a county listing also. I want to have the results put the records that have hcounty matches first, then the records that have a county match in the comments field after the first set of records. I have tried all sorts of order by and group by and can't get the result I'm looking for....

View Replies !
ORDER BY :: Sequence Order
Is it possible to ORDER BY based on the sequence order, for instance I use this Query:

SELECT * FROM Showroom WHERE Artnumber IN (52900, 52536, 52730)

the result is this:

Artnumber Price
52536 25,80
52730 1,90
52900 31,10

View Replies !
Order By Unconventional Order
How can I have letter "z" comes before letter "a" when I select my items from a table. I need my list to show (z, a, b, c, d, ...).

Also, how can I have numbers come after letters, say, if I want my list to be ( z, a, b, c, ... 1, 2, 3, ...)

View Replies !
ORDER BY Out Of Order - Fixed
I have a query that uses two tables that I want to produce output like the following:

+-------------+-------------+-----------+
| LOCATION | GROSS SALES | NET SALES |
+-------------+-------------+-----------+
| Location 1 | 11,860,735 | 2,907,552 |
| Location 4 | 4,814,029 | 1,077,003 |
| Location 3 | 2,711,795 | 710,804 |
| Location 5 | 2,660,040 | 666,255 |
| Location 2 | 2,049,470 | 563,830 |
| Location 8 | 2,227,730 | 543,220 |
| Location 7 | 1,766,880 | 425,483 |
| Location 6 | 1,721,681 | 367,252 |
| Location 10 | 13,424 | 2,253 |
+-------------+-------------+-----------+

However, I cannot get the "order by" part of the statement to work. I have tried adding a zero to the order by alias. And when I attempt to specify the field in the order by with the calculation and not the alias I get an error.

The following examples are queries without the zero and with a zero added to the alias in the order by line. I have also added the details for the table below for reference. Code:

View Replies !
Custom Order For ORDER BY
I'm grabbing six specific records, like so:

$result = mysql_query("SELECT * FROM casestudies WHERE id=1 OR id=2 OR id=3 OR id=4 OR id=5 OR id=6 ORDER BY ___________",$db);

I'd like to post them in a custom order, specifically: 1,3,4,5,6,2. Can't figure out how to do this with ORDER BY, if that's even possible. Anything I'm missing?

View Replies !
Force Order By Order??
I have 6 rows of data... each has a name, eg: c1, c2, mrgs1, totalfte.
they are all under the one column "field". Is there a way I can force their order??

at the mo, I use "ORDER BY field DESC" and its coming out lile

mrgs1, totalfte, c1, c2

I need

totalfte, mrgs1, c1, c2

is it possible to sort like this??

View Replies !
Order By Ascending Order
I have a mysql table with a column with a few zero values and an ordered list of numbers.. eg 0,0,0,1,2,3,4,5

is there a way to order the table in ascending order for the numbers 1-5 then display the ones with zero afterwards in one sql query..

so it would turn out like 1,2,3,4,5,0,0,0

View Replies !
Order Of Table Joins Or Where Clauses Relevant
As we're on this topic in another thread right now:

Say I have a SELECT query from more than one table and with some =
conditions, does it matter in what order I enter the tables in the FROM =
clause and in what order the WHERE conditions appear in my query? Or =
does it make any difference if I use WHERE or HAVING? (I see that MS =
Access likes those HAVINGs...)

Of course my tables contain (maybe very much) more than some 100 records =
and are well-indexed, I believe.... but that's not my question for now.

I guess, the MySQL optimizer reads the table and column names in the =
specified order and tries to process them the same way, right? Or it =
joins the tables in my given order... And when are the resulting records =
reduced by matching against my conditions? Maybe someone can tell me a =
little bit about performance gains just by doing some 'manual query =
optimization'.

View Replies !
MyISAM Table And Sort Order On The Disk
I ran the myisamchk tool with the options --sort-index --sort-records=1 against an MYI file. Is there something I can use to confirm what this command did? I would like to see what the sort order
on the disk for each table in my database.

View Replies !
Have My Recordset Table Show Up In Random Order
I have the following code on my PHP page and my goal is to have the recordset show up in a random order each time the page is visited. I have tried a ORDER BY RAND() and come up with errors only. Is there anyway to find out what code I need to use and where I would place it in this piece of code? Code:

View Replies !
Order A Union Select Using Joined Table Row
I am having trouble sorting this select using the "model name" which is from "inventory_model.model".

The following gives me this error "Table 'm' from one of the SELECTs cannot be used in global ORDER clause".

If I removed the order line (ORDER BY m.model DESC), the query works fine with no errors, but the results are not alphabetical, they are rather random.

PHP

$selectM = mysql_query("
(select i.id, i.Model, m.Model
   from inventory i, inventory_category c, inventory_model m  
  where (i.catid=c.id AND c.parent=&#3947;') AND i.Make='$id' AND i.Model=m.id AND i.I_IC_C_S!='S' AND i.N_U_R_C!='C' GROUP BY i.Model)
  union all
(select i_sub.id, i_af.model, m.model
   from inventory i_real
   join inventory_alsofits i_af
     on i_af.itemid = i_real.id  
   join inventory i_sub
     on i_af.itemid = i_sub.id
   join inventory_category c_real
     on i_real.catid = c_real.id
   join inventory_model m  
     on i_af.model = m.id
  where i_af.make='$id' AND c_real.parent=47 AND i_real.I_IC_C_S!='S' AND i_real.N_U_R_C!='C' GROUP BY i_af.model)
  ORDER BY m.model DESC
  ") or die(mysql_error());

View Replies !
Weird Problem With A Largish Table Order By
(and gals),
Just wondering if any of you could shed some light on a weird problem i'm getting with mysql 5.0.41

The table in question has a row count of 1598097

mysql> describe select isbn from titles
-> order by author
-> limit 1598097;
+----+-------------+---------+------+---------------+------+---------+------+---------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+---------+----------------+
| 1 | SIMPLE | titles | ALL | NULL | NULL | NULL | NULL | 1598097 | Using filesort |
+----+-------------+---------+------+---------------+------+---------+------+---------+----------------+
1 row in set (0.00 sec)

mysql> describe select isbn from titles
-> order by author
-> limit 1598096;
+----+-------------+---------+-------+---------------+--------------+---------+------+---------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------------+---------+------+---------+-------+
| 1 | SIMPLE | titles | index | NULL | Index_Author | 43 | NULL | 1598097 | |
+----+-------------+---------+-------+---------------+--------------+---------+------+---------+-------+
1 row in set (0.00 sec)

The first select statement obviously runs extremely slow. I can solve the problem with a "force index (index_author)" command... But just wondering what's going through the mind of MySQL!!??

View Replies !
Create Table / Column Table Order
When creating a table, is there any advantage in specifying the columns in
any special order? For example, what about columns with data used more
frequently listed first, or column/data types giving some? Or.... am I being
pedantic even thinking about such?

View Replies !
Phpmyadmin Export Problem With Order Of Table Creation
This is a phpmyadmin question more than anything, but I hope someone may be
able to help. When creating a dump of a normalized database with 26 innodb
tables, phpmyadmin export seems to only export the table structure/data in
alphabetical order, rather than FK contraint order.

Thus when importing the
dump of the data, I need to manually go through and select the order to make
sure the constraints hold up. Has anyone else seen this? I'm running
phpmyadmin 2.5.4 on both linux and win xp.

View Replies !
'order By Alternating Table' Results And 'begins With' Select
I am just starting to learn SQL and have been working on a couple of questions and yes this is homework related. I am having trouble with 3 questions. I have the basis for the answers but am stuck on a couple of points.

I don't expect a direct answer but a push in the right direction would be helpful. Also, if anyone can recommend additional resources for assisting with learning SQL, that would be great. The first question is as follows:

A company is preparing invitations to its annual holiday celebration and wants to invite its sales staff (everyone in the SALESREPS table) and its customers (everyone in the CUSTOMERS table). Write a SQL statement that returns output looking like the following (including the sort order): Code:

View Replies !
Order By Count Of Occurrences In 2nd Table Without Nested Query (MySQL 4.0.27 Workaround)
My ISP is using an old version of MySQL, 4.0.27-max-log. I am using a query that runs fine on my test-server (MySQL 5.0.70-log). The main point of this query is to return an ordered list of volunteers for job assignment. One of the metrics is the number appearances in an activity table. I am using a nested query to COUNT the number of appearances during a specific time window to obtain this metric, but this approach does not appear to work in 4.0.27.

Is there a simpler or alternative query that will make 4.0.27 happy?

SELECT job10.person_id, people.history, job10.history, (

SELECT COUNT( * ) FROM activity WHERE activity.person_id = people.person_id AND (activity.day = '2009-2-1' OR activity.day = DATE_ADD( '2009-2-1', INTERVAL 3 DAY))

) AS appearances, CONCAT( first_name, ' ', last_name ) AS name
FROM duty_sing_am INNER JOIN duty_people USING ( person_id )
WHERE people.active AND job10.willingness > 0
ORDER BY appearances, job10.history, people.history, job10.person_id

View Replies !
ALTER TABLE Table ORDER BY ...
I have managed to create a database of 4.2 million rows. There
are a few varchar fields and a couple of them are indexed with
fulltext. Plus there are four numeric fields.

I discovered when I only had about 400,000 rows that I could
skim the top most 200 likely matches off the database with
fulltext by first sorting the table with ALTER TABLE and then
using a LIMIT 200. Since my data was not being added top the
data was remaining sorted and this worked very quickly.

But I just added another 3.8 million records and issued the
command:

* ALTER TABLE indexed ORDER BY (urank+blinks-quality-spareint) DESC;

We are now about 11 hours later and SHOW PROCESSLIST is
reporting a state of:

* Repair with keycache

Any idea how many more hours I might expect to wait for it
to finish? If it might be a very long time is there a simpler
way to do this? I have MySQL 5.0.27 and tried the following:

* SELECT hash,url,title,decription,text,urank FROM indexed WHERE hash IN (SELECT hash FROM indexed where MATCH(title,text) AGAINST('keyword1 keyword2') LIMIT 200) ORDER BY urank DESC;

But it tells me that LIMIT is not allowed with the IN function.

View Replies !
Unable To Include #include&lt;mysql++.h&gt;
I am unable to include #include<mysql++.h> in C++ project under windows platform.

I am using Eclipse IDE. and i have added all the headers files MYSQL 5.1 is also installed on my system. i have searched the complete dir. but i am unable to find <mysql++.h>.

..Application.h:32:28: mysql++/mysql++.h: No such file or directory
Build error occurred, build is stopped

I searched the complete directory but unable to locate the file...

View Replies !
Include A Table Into Another
whether this is possible straight inside the database.
On this new website i 'm working on, there are projects, and there is a news section.

Each news article will belong to one of the projects, or to 2 other categories ("General" - "website-related"), possibly more in the future.

I'd like to keep the "projects" table strictly for projects, so i was wondering if it would be possible to have another table "news_categories" contain the "projects" table at all times.
If not, i guess i can unify the two when querying the database_

View Replies !
SQL Query To Include Count From Associated Table
I am having a tough time coming up with the sql for the statement but the long and short of it is this:

Two Tables:

Table 1 is a group - Table 2 is a list of items that belong to a group from table 1.

I want to query all (*) information from table 1 AND get the count of the number of associated items from that group from table 2 in that same query.

View Replies !
Alter Table To Include Fulltext Indexes
I am trying to make a search page for a database of articles. I am going to use fulltext indexes on the table to make the search faster and so that I can order results by relevance. Here is my table:

ARTICLES
- id (int, auto increment, primary key)
- authors (varchar)
- title (varchar)
- year (int)
- keywords (text)

I want the users to be able to choose (via a dropdown box) whether they want to search by author, title, OR keyword. Not all of them at the same time. So, some example select statements would be:

SELECT * FROM articles WHERE MATCH (authors) AGAINST ('Smith');
SELECT * FROM articles WHERE MATCH (title) AGAINST ('Computer');

So how do I alter the table to include the Fulltext indexes? Do I do one fulltext like this: ALTER TABLE articles ADD FULLTEXT my_ft (authors, title, keywords);

or do I need to do seperate alters like this:
ALTER TABLE articles ADD FULLTEXT my_ft1 (authors);
ALTER TABLE articles ADD FULLTEXT my_ft2 (title);
ALTER TABLE articles ADD FULLTEXT my_ft3 (keywords);

View Replies !
"hard" Sort Table Order
Is it possible to resort the rows in a table like in a query where using ORDER BY, but have to new sort order stored in the table structure?

View Replies !
Updating A Table Via Select, But Include Current Date
I have a table that's collecting the number of times a sponsor logo is shown and clicked. I'd like to run a daily job to gather that info into a separate table for later report generation.

The report table has id, date, shown, clicked as fields and all of those except the date come from a second table.

So, I'd like to run a job daily that does something similar to the following:

update s_r (id, date=TODAY(), shown, clicked) from (select id, shown clicked) from s;

I'm generally familiar with database work but don't have deep knowledge (yet :) and I evidently don't have my search skills tuned for database questions yet.

View Replies !
1st Letter As UPPER Rest As LOWER
How can I update the first letter in each word in a column as an UPPERCASE and the rest of the letters as LOWERCASE?

ie: john doe = John Doe

UPDATE contacts SET name =??

FYI my Table is 'contacts'
the column is 'name'

View Replies !
Table Named "order"
I'm getting errors when running queries or even simple mysql commands like "describe order" on a table named "order". I'm guessing it's because "order" is a keyword. How should I access the table correctly?

View Replies !
How To Discard Rows Of A Text File Which Does Not Satisfies Foreign Key Constraint And Continue With The Rest
I am loading data to a child table from a text file. the text files
also contains data not referenced by parent key. while loading the data
if one row fails to satisfies the constraint everything is getting
rollback..

plz suggest me something.. which will help me to discard the
unsatisfied rows and continue with the rest..

My Query:
LOAD DATA CONCURRENT INFILE
'/remote/srm172/saranya/SOURCECOV/common_shell/output/data/common_shell_exec.dat'
INTO TABLE CS_COMMON_SHELL_EXEC_REG FIELDS TERMINATED BY '#'
(reg_id,func_address);

Error Msg:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key
constraint fails (`sourcecov/CS_COMMON_SHELL_EXEC_REG`, CONSTRAINT
`CS_COMMON_SHELL_EXEC_REG_ibfk_2` FOREIGN KEY (`func_address`)
REFERENCES `CS_COMMON_SHELL_EXEC` (`func_address`))

View Replies !
ORDER BY A Set
I want to order a result set by a specific order, rather than just ascending or descending alphabetically/numerically. For example if I have a table called region

idName
1London
2Scotland
3Wales
4Midlands
..
..
..

but I want them ordered so that the result is Scotland, London, Wales,
Midlands,... can I use some sort of set in the order by clause?

Something like:
select name from region order by id {2,1,3,4};

I haven't used mysql SETs before so not sure if they can be applied here.

View Replies !
Order By Str To Int
Hi jave a database and I want to oder my result by a colum containing
string bit order them like they where int

ex Select * form members order by level

level is string containing data like '12'

I want to oder like the level is Int 12 and not string '12'

View Replies !
Order By OR
Lets say I have a query similar to:

SELECT * FROM company WHERE id='3' OR id='1' OR id='7' ;

I want to be able to get the results to come out ordered by the order
the ids were searched (the sequence in the WHERE OR; 3 first then 1,
then 7.), so the results would be like:

Row | id| name
-------------------
0| 3| Joe's Co
1| 1| Buymart
2| 7| The big evil

As it is the results returns it like id 1, then 3, and 7.

View Replies !

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