Re: [PHP-DB] SQL question!
I have these tables. Users ( id,name,etc ) Coments : ( id , comment ) How do I do this kind of query: I thought in one thing like this but I cant figure it out. Example: Select * from users order by id desc in (select count (id) from comments) Expected result: List of users: * User1 See comments ( 32 comment in database ) * User2 See coments (13 comments in database ) You need to add a user_id column to comments, which records what user entered each comment. Then you can do SELECT u.name, COUNT(c.id) FROM users u, comments c WHERE u.id=c.user_id GROUP BY (c.user_id) The syntax may not be exactly right but that's the basic idea. Adding a user ID foreign key to the comments table is the important part. Hope that helps, Larry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SQL question!
Hey. I have these tables. Users ( id,name,etc ) Coments : ( id , comment ) How do I do this kind of query: I thought in one thing like this but I cant figure it out. Example: Select * from users order by id desc in (select count (id) from comments) Expected result: List of users: * User1 See comments ( 32 comment in database ) * User2 See coments (13 comments in database ) * etc. thanks in advanced. Bruno
[PHP-DB] SQL question
I know it is possible to search a database like this: SELECT * FROM x_table WHERE name=%part_of_name% but I don't know for sure the correct command. Could you tell me the right syntax? TIA Aurel. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL question
It should be as follows: SELECT * FROM x_table WHERE name Like = %part_of_name% Hope this helps, M.Mamedov - Original Message - From: Constantin Brinzoi [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, December 11, 2003 1:51 PM Subject: [PHP-DB] SQL question I know it is possible to search a database like this: SELECT * FROM x_table WHERE name=%part_of_name% but I don't know for sure the correct command. Could you tell me the right syntax? TIA Aurel. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.545 / Virus Database: 339 - Release Date: 27.11.2003 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] SQL question
try SELECT * FROM x_table WHERE name LIKE %part_of_name% -Original Message- From: Constantin Brinzoi [mailto:[EMAIL PROTECTED] Sent: 11 December 2003 11:52 To: [EMAIL PROTECTED] Subject: [PHP-DB] SQL question I know it is possible to search a database like this: SELECT * FROM x_table WHERE name=%part_of_name% but I don't know for sure the correct command. Could you tell me the right syntax? TIA Aurel. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Email has been scanned for viruses by www.emf-systems.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL question
I am sorry without equal = sign SELECT * FROM x_table WHERE name Like %part_of_name% there are actually three ways to do this: %part_of_name% part_of_name appears anywhere %part_of_namepart_of_name appears at the end art_of_name% part_of_name appears at the begining M.Mamedov - Original Message - From: Muhammed Mamedov [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, December 11, 2003 2:00 PM Subject: Re: [PHP-DB] SQL question It should be as follows: SELECT * FROM x_table WHERE name Like = %part_of_name% Hope this helps, M.Mamedov - Original Message - From: Constantin Brinzoi [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, December 11, 2003 1:51 PM Subject: [PHP-DB] SQL question I know it is possible to search a database like this: SELECT * FROM x_table WHERE name=%part_of_name% but I don't know for sure the correct command. Could you tell me the right syntax? TIA Aurel. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.545 / Virus Database: 339 - Release Date: 27.11.2003 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.545 / Virus Database: 339 - Release Date: 27.11.2003 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SQL question!
Hi, I need a sql query to join multiple lines into only one line. Ok, I wouldn´t understand this question so I´ll give an example (I´m doing it on mysql but I need it to mssql). Supose I have 3 tables: mysql select * from test1; ++---+ | id| nome | ++---+ | 1| Bruno | | 2| Jorge | ++---+ mysql select * from test2; ++-+---+ | id| request | value | ++-+---+ | 1| 1 | 100,00 | | 1| 2 | Mercedes | | 2| 1 | 50,00| | 2| 3 | Sparc Sun | ++-+---+ mysql select * from test3; ++--+ | id| value| ++--+ | 1| money | | 2| car | | 3| computer | ++--+ test1.id - test2.id test3.id - test2.request When I execute: select test1.nome, test3.value, test2.value from test1, test2, test3 where test1.id = test2.id AND test2.request = test3.id I get: +---+--+---+ | nome| value | value | +---+--+---+ | Bruno | money | 100,00 | | Bruno | car | Mercedes | | Jorge | money | 50,00| | Jorge | computer | Sparc Sun | +---+--+---+ But I need this result: +---+--+---++ | nome| money | car| computer| +---+--+---++ | Bruno | 100,00 | Mercedes | NULL| | Jorge | 50,00 | NULL | Sparc Sun | +---+--+---++ Is it possible in Microsoft SQL Server? I´d like to know if it can be executed on mysql and, if not, if there is some way to do it in mysql. Sorry for the big e-mail but it´s something I really need to know. Thank´s Bruno Gimenes Pereti. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SQL Question
Hello, I have a simple SQL Question. I would like to take the column city in database addresses and find out which cities are available in it. In other words if the following values are in there: city El Paso Burlington New York New York El Paso Burlington I would like it to return El Paso New York Burlington I know that it would something like SELECT `city` FROM `addresses` WHERE ?? Thanks Kevin Diffily InterNetWorkingSolutions Enterprise Class Solutions for All Enterprises 318 Last Road, Cabot, VT 05647 USA VOICE: 1.866.inetws.net (Toll Free) FAX: 1.888.726.9030? (Toll Free) Sales: [EMAIL PROTECTED] General Information:[EMAIL PROTECTED] Website Hosting:[EMAIL PROTECTED] Systems Administration Services: [EMAIL PROTECTED] Technical Support Training Services: [EMAIL PROTECTED] Shop For it On Amazon:http://kevin.inetws.net/amazon Instant Messaging Username: AIM, IRC, Jabber, MSN, Yahoo: inetwsnet ICQ: 120778694
RE: [PHP-DB] SQL Question
SELECT DISTINCT city FROM addresses; -Original Message- From: Kevin Diffily [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 13, 2002 1:05 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] SQL Question Hello, I have a simple SQL Question. I would like to take the column city in database addresses and find out which cities are available in it. In other words if the following values are in there: city El Paso Burlington New York New York El Paso Burlington I would like it to return El Paso New York Burlington I know that it would something like SELECT `city` FROM `addresses` WHERE ?? Thanks Kevin Diffily InterNetWorkingSolutions Enterprise Class Solutions for All Enterprises 318 Last Road, Cabot, VT 05647 USA VOICE: 1.866.inetws.net (Toll Free) FAX: 1.888.726.9030? (Toll Free) Sales: [EMAIL PROTECTED] General Information:[EMAIL PROTECTED] Website Hosting:[EMAIL PROTECTED] Systems Administration Services: [EMAIL PROTECTED] Technical Support Training Services: [EMAIL PROTECTED] Shop For it On Amazon:http://kevin.inetws.net/amazon Instant Messaging Username: AIM, IRC, Jabber, MSN, Yahoo: inetwsnet ICQ: 120778694 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] SQL Question
you can do it by using distinct function .. Do: SELECT DISTINCT(city) FROM addresses; Gurhan -Original Message- From: Kevin Diffily [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 13, 2002 2:05 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] SQL Question Hello, I have a simple SQL Question. I would like to take the column city in database addresses and find out which cities are available in it. In other words if the following values are in there: city El Paso Burlington New York New York El Paso Burlington I would like it to return El Paso New York Burlington I know that it would something like SELECT `city` FROM `addresses` WHERE ?? Thanks Kevin Diffily InterNetWorkingSolutions Enterprise Class Solutions for All Enterprises 318 Last Road, Cabot, VT 05647 USA VOICE: 1.866.inetws.net (Toll Free) FAX: 1.888.726.9030? (Toll Free) Sales: [EMAIL PROTECTED] General Information:[EMAIL PROTECTED] Website Hosting:[EMAIL PROTECTED] Systems Administration Services: [EMAIL PROTECTED] Technical Support Training Services: [EMAIL PROTECTED] Shop For it On Amazon:http://kevin.inetws.net/amazon Instant Messaging Username: AIM, IRC, Jabber, MSN, Yahoo: inetwsnet ICQ: 120778694 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php