mysql query multiple records for one field


 
Thread Tools Search this Thread
Top Forums Programming mysql query multiple records for one field
# 1  
Old 05-07-2012
mysql query multiple records for one field

Hello Group,

What I have is a database with about a dozen fields and one being "City".

What I would like to do is to have a custom query on a single field for multiple items (cities) but I don't know how to do this. I know this is probably kids play for most of you but I am lost. What I have got to work is a single city from the list but I do not know how to "ADD", "OR" or what I need to do next to add a second city so the results displayed contain both cities.

What I have so far is this:

Code:
SELECT MyList.`Filed Date` AS `Filed Date`,
  MyList.City AS City,
  MyList.State AS State,
  MyList.`Zip Code` AS `Zip Code`,
  MyList.Street AS Street,
  MyList.Owner AS Owner
FROM MyList
WHERE MyList.City = _latin1'Buffalo'

Not sure what to add to the WHERE to add more city names other than "Buffalo" to the "City" field.Smilie



Thanks in advance for any replies!


Art
# 2  
Old 05-07-2012
Code:
SELECT MyList.`Filed Date` AS `Filed Date`,
  MyList.City AS City,
  MyList.State AS State,
  MyList.`Zip Code` AS `Zip Code`,
  MyList.Street AS Street,
  MyList.Owner AS Owner
FROM MyList
WHERE MyList.City in ( 
  a_comma_separated_list_of_values_here
  );

This User Gave Thanks to radoulov For This Post:
# 3  
Old 05-07-2012
radoulov,

Thank you!

That works fine. Is there any way to specify a sort order as the output I get is mixed together in random order or using another column to sort between all cities I specify. If not that is fine but having all the ducks in a row would be best.

Thanks again!

Art
# 4  
Old 05-07-2012
Just add an order by clause:

Code:
...
WHERE MyList.City in ( 
  a_comma_separated_list_of_values_here
  )
order by 
  MyList.City (or some other column or expression)

This User Gave Thanks to radoulov For This Post:
# 5  
Old 05-07-2012
Sorry for the questions. I know this is basic stuff. I use RAD software for development and doing anything extra like this is off the wall for me.

Thank you once again!


ArtSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

MYSQL Query for last twelve months of records

Hi I am trying to run a MYSQL query to display all records within a 12 month period. I have to use from_unixtime function to great a date object. select call_start_time from call_detail_records where call_start_time IN ( select from_unixtime(call_start_time) from call_detail_records ... (3 Replies)
Discussion started by: mojoman
3 Replies

2. Programming

Need help in mysql query

Hi All, i have a table in mysql with the following data Table name Test Assettype Serial_No Status location Mouse 123456 In Stock chennai Mouse 98765 Allocated chennai Keyboard ... (2 Replies)
Discussion started by: venkitesh
2 Replies

3. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

4. Programming

mysql query help

Hello i have created mysql query to compare to values and get difference in percentage as following: SELECT file_name, 100 - ((100 * (SELECT file_count FROM xipi_files z WHERE x.file_group = z.file_group AND x.file_name = z.file_name AND z.insert_date = CURDATE( ) - INTERVAL 1 DAY)) /... (1 Reply)
Discussion started by: mogabr
1 Replies

5. Web Development

mysql query for multiple columns from multiple tables in a DB

Say I have two tables like below.. status HId sName dName StartTime EndTime 1 E E 9:10 10:10 2 E F 9:15 10:15 3 G H 9:17 10:00 logic Id devName capacity free Line 1 E 123 34 1 2 E 345 ... (3 Replies)
Discussion started by: ilan
3 Replies

6. Web Development

mysql query help

hello all i have 2 columns every column in the following format column1 2011-04-01 11:39:54 column2 2019-02-03 00:00:00 i want get difference between above data as following 2 days 11:39 how to do so ? i tried many functions but nothing works please advice what is the query... (6 Replies)
Discussion started by: mogabr
6 Replies

7. Shell Programming and Scripting

bash assign mysql query single field to variable

I'm running a bash script query and assigning the output to a variable like this: exists=`mysql -u $USER_NAME --password=$PASSWORD -D "somedb" \ -e "SELECT * FROM somedb.sometable WHERE field1 ='$a' \ AND field2 ='$b' LIMIT 0 , 30";` which returns something like: echo... (2 Replies)
Discussion started by: unclecameron
2 Replies

8. Programming

How to query one to many mysql

Hi there, I have a hierarchical database that include 4 tables. Table A is the parent of B, B is Parent of C, C is parent of D. If I want to query everything in D that is associated with A.name, how do I do that? Thanks! YanYan (0 Replies)
Discussion started by: pinkgladiator
0 Replies
Login or Register to Ask a Question