Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHERE-ing for multiple records 3

Status
Not open for further replies.

kupe

Technical User
Sep 23, 2002
376
If I say

SELECT * FROM table WHERE ID = 1 AND ID = 10;

I just get the one record. Be grateful to know the secret for selecting multiple records with a WHERE clause.

 
With that statement you'll get no records!

If you say WHERE ID=1 , you'll get all records where ID=1. If you say WHERE ID=1 OR ID=10 , you'll get all records with ID=1 or ID=10. If you say WHERE ID BETWEEN 1 AND 10 , you'll get all records where ID is between 1 and 10 inclusive.

This is just the tip of the iceberg though. It's impossible to explain all your options here. You would need to get yourself a book about SQL, preferably MySQL.
 
You might be most interested in an in clause:

Code:
SELECT *
FROM table
WHERE ID In (1, 10)
 
Thanks very much, Tony and Dalchri. Well noted, thank you. Tony, I have, Paul DuBois's. But I didn't find the answer to this question, and a lot of others. (I want to use php with mysql, but so far I haven't been able to get both working on the same machine.)
 
Tony and dalchri

Worked really well, thanks very much.

Now I need to trim some of the string length. Trim(), it seems, will only chop spaces and the like.

Can I reduce a string, or is it only possible by changing the attributes for that column, please?
 
If you have Paul Du Bois's book, you could turn to page 813 and find the LEFT function, which you could use as follows:
[tt]
UPDATE tbl1 SET col1=LEFT(col1,10);
[/tt]
That will simply reduce the length of the strings in the column to a maximum of 10, but still leave it possible to store full-length strings in the column. If you want to change the length of strings that can be stored in the column, you could use:
[tt]
ALTER TABLE tbl1 MODIFY col1 CHAR(10);
[/tt]
 
That's perfect, Tony. Thanks very much. Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top