简体   繁体   中英

Stuck with SQL query “select from table where column ”

I am trying to make a query for a very small task. for example: I have two column "Name" and "Cash", here is some sample data:

Cash     Name
100      mr. A
110      mr. A
150      mr. A
120      mr. A
200      mr. B
220      mr. B
202      mr. B
300      mr. C

Now I need to make a query for 220(Cash) which will search the full database, I was try lite that;

SELECT * FROM `tbl_cash` 
WHERE `cash`='220' AND `name` = 'mr. B' OR `name` = 'mr. A' OR `name` = 'mr. C'

But it's not work. As I need to search the full database for match name and cash and then it should output the correct value.

try this- use the IN operator, it allows you to specify multiple values in a WHERE clause:

SELECT * FROM `tbl_cash` 
WHERE `cash`='220' AND `name` IN ('mr. B','mr. A','mr. C')

you mean

SELECT * FROM tbl_cash WHERE cash='220' 

or

 SELECT * FROM `tbl_cash` WHERE cash='220' AND (name = 'mr. B' OR name = 'mr. A' OR name = 'mr. C')

or

 SELECT * FROM `tbl_cash` WHERE cash='220' AND (name like 'mr.%')

Simply try using IN operator as

SELECT * FROM `tbl_cash` 
WHERE `cash`='220' AND `name` IN('mr. B','mr. A','mr. C')

用这个

SELECT * FROM tbl_cash WHERE cash='220' AND name IN('mr. A', 'mr. B', 'mr. C') GROUP BY cash, name

SELECT * FROM tbl_cash cash = 220并name 'mr。%')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM