SQL Help

Status
Not open for further replies.

Funny

Active Member
521
2011
66
0
This is a easy code but I am not able to figure it as Im fairly new to SQL.

Example I have a table like this-
Name: ID:
abcde 1
efghia 3
pofjsa 5
asklda 6

I want to sort the tables according to increasing ID.
Like this-
Name: ID:
abcde 1
efghia 2
pofjsa 3
asklda 4


Assuming that the ID's are continuously increasing but there are some ID's missing like 11,14,15,16,17,20,21.. etc

Thanks :)
 
16 comments
Just to add to the above you can have ORDER BY something DESC or ORDER BY something ASC
which means you can have it decreasing (DESC) or ascending (ASC)
 
This is a easy code but I am not able to figure it as Im fairly new to SQL.

Example I have a table like this-
Name: ID:
abcde 1
efghia 3
pofjsa 5
asklda 6

I want to sort the tables according to increasing ID.
Like this-
Name: ID:
abcde 1
efghia 2
pofjsa 3
asklda 4


Assuming that the ID's are continuously increasing but there are some ID's missing like 11,14,15,16,17,20,21.. etc

Thanks :)

He said he wanted it by id. check his quote again. :)

And I guess you can use this link http://php.about.com/od/learnmysql/p/SQL_order_by.htm and one for reading http://www.rif.org/
 
Last edited:
You are welcome and for the update..
try this one:
PHP:
UPDATE `url` SET `destination`=concat("http://",`destination`) WHERE `destination` NOT LIKE 'http%'

PS backticks are a pain and most systems work without them.

so it could be simply:
PHP:
UPDATE url SET destination=concat("http://",destination) WHERE destination NOT LIKE 'http%'

BY the way when you use + mysql tries to add..

when you use || it means or not concat...
 
Last edited:
@ Halcyon- That didn't work.

@ Lock Down- It worked actually. Thanks a ton. +rep
Btw it was not working when there was double quotes in "http://", i changed it to 'http://' and it worked like a charm! :)
 
Also is there a way to do this in php-
If 'destination' is not like 'http://%' then concat 'http://' and destination and store it in destination itself, that is: destination=http://+destination
 
PHP:
$destination = array('http://www.wjunction.com/92-development-area/128851-sql-help-2.htm#post1400928',
'URL2.com',
'URL3.com',
'http://url4.com',
'http://www.url5.com'
);
var_dump($destination);
echo '$destination by default <br />';
foreach($destination as $destine) {
if(!strstr($destine, 'http://')){
echo '</b>http://'.$destine.'</b> Not found so i included<br />';
$destination2[] = 'http://'.$destine;
}else{
echo 'YES - Found http:// in <b>'.$destine.'</b><br />';
$destination2[] = $destine; 
}
}
echo '<br />the new array whith http:// on all values <br/>';
var_dump($destination2);
 
Last edited:
Last edited:
Status
Not open for further replies.
Back
Top