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
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_name"part_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
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
On 11 December 2003 11:52, Constantin Brinzoi wrote: > 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? SELECT * FROM x_table WHERE name LIKE "%part_of_name%" Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- 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
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
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