mysql how to select a specific row from a table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mysql how to select a specific row from a table
# 1  
Old 12-10-2010
mysql how to select a specific row from a table

i have a table

records
------------
id | user | time | event
91 admin | 12:00 | hi
92 admin | 11:00 | hi
93 admin | 12:00 | bye
94 admin | 13:00 | bye
95 root | 12:00 | hi
96 root | 12:30 | hi
97 root | 12:56 | hi

how could i only select and display only the user and event from times between 12:00-12:30? (and sort them by id if i can)

so it would show

91 admin hi
93 admin bye
95 root hi
96 root hi

when i use select user, host from record LIMIT 1;
it only displays the first.
kinda lost! help plwould be appreciated!
# 2  
Old 12-10-2010
Code:
$ awk '{gsub(":","",$4)};$4>=1200&&$4<=1230{print $1,$2,$NF}' file

# 3  
Old 12-10-2010
that is a mysql command?
# 4  
Old 12-10-2010
Not got SQL on this machine but try

Code:
SELECT user, host FROM record WHERE time >= 12:00 AND time <= 12:30;

# 5  
Old 12-10-2010
I think you need to add quotes:

Code:
select user, host from records where time between "12:00" and "12:30";

But that won't work either since the field "host" does not exist.

Last edited by verdepollo; 12-10-2010 at 06:33 PM.. Reason: missing ";"
This User Gave Thanks to verdepollo For This Post:
# 6  
Old 12-10-2010
Good spot Smilie

So your probably after

Code:
SELECT id, user FROM record WHERE time >= "12:00" AND time <= "12:30";

This User Gave Thanks to robfwauk For This Post:
# 7  
Old 12-20-2010
know this is late but thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to convert table-by-row to matrix table

Hello, I need some help to reformat this table-by-row to matrix? infile: site1 A:o,p,q,r,s,t site1 C:y,u site1 T:v,w site1 -:x,z site2 A:p,r,t,v,w,z site2 C:u,y site2 G:q,s site2 -:o,x site3 A:o,q,s,t,u,z site3 C:y site3 T:v,w,x site3 -:p,routfile: SITE o p q r s t v u w x y... (7 Replies)
Discussion started by: yifangt
7 Replies

2. Emergency UNIX and Linux Support

[Solved] Mysql - Take data from row and copy it to another row

Sorry if I repost my question in this section, but I'm really in a hurry since I have to finish my work... :( Dear community, I have a table with two rows like: Row1 Row2 ======= ======= 7,3 text 1 1,3 text 2 1,2,3 blabla What i need to do is add/copy... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

3. Shell Programming and Scripting

In php, Moving a new row to another table and deleting old row

Hi, I already succeed moving a new row to another table if the field from new row doesn't have the first word that I categorized (like: IRC blablabla, PTM blablabla, ADM blablabla, BS blablabla). But it can't delete the old row. Please help me with the script. my php script: INSERT INTO... (2 Replies)
Discussion started by: jazzyzha
2 Replies

4. Shell Programming and Scripting

Moving new row and deleting old row to another table

Hi, I want to move a new row to another table if the field from new row doesn't have the first word that I categorized (like: IRC blablabla, PTM blablabla, ADM blablabla, BS blablabla). I already use this script but doesn't work as I expected. CHECK_KEYWORD="$( mysql -uroot -p123456 smsd -N... (7 Replies)
Discussion started by: jazzyzha
7 Replies

5. UNIX for Dummies Questions & Answers

Select 2 columns and transpose row by row

Hi, I have a tab-delimited file as follows: 1 1 2 2 3 3 4 4 a a b b c c d d 5 5 6 6 7 7 8 8 e e f f g g h h 9 9 10 10 11 11 12 12 i i j j k k l l 13 13 14 14 15 15 16 16 m m n n o o p p The output I need is: 1 1 a a 5 5 e e 9 9 i i 13... (5 Replies)
Discussion started by: mvaishnav
5 Replies

6. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

7. Web Development

MySQL Master-Slave Configuration: Don't Replicate a Row of a Table?

Anyone have a clue about this? I have checked the MySQL documentation and it does not seem possible to exclude a row of a table from replication between Master and Slave. It seems that replication in MySQL can only be managed at the table level, not at the row level. Does anyone know a work... (5 Replies)
Discussion started by: Neo
5 Replies

8. Programming

Select several minimum values from row (MySQL)

Hello there. I've got the query like that SELECT count(tour_id) AS cnt FROM orders JOIN tours ON orders.tour_id=tours.id GROUP BY tour_id The result Is cnt 1 4 2 1 1 Now i have to select all records with minimum values in field "cnt" MySQL function min() returns only one.... (2 Replies)
Discussion started by: Trump
2 Replies

9. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies
Login or Register to Ask a Question