What does the below query explain?
What does the below query explain?
SELECT * FROM `jos_menu` WHERE (id = 69 OR id = 72)
I know its very si开发者_开发技巧lly question, but sometimes easy things creates mess in my skulls interpreter.. Pls help
EDIT
Its giving me record for both IDs, why is it doing so? It should five me the record for either 69 or 72....
I think you mean "Explain what the below query does", which I'll do:
- Return data from all of the columns in the
jos_menu
table. Return all rows whose id's are 69. Also return all rows whose id's are 72.
Essentially what it does is it goes through each row and checks:
- Does this row have an id of either 69 or 72? If yes to either one, add it to the list of items returned.
- Does this row have an id of either 69 or 72? If yes to either one, add it to the list of items returned.
- Does this row have an id of either 69 or 72? If yes to either one, add it to the list of items returned.
etc..
SELECT *
Get the values of every column
FROM `jos_menu`
From a table called "jos_menu"
WHERE (id = 69 OR id = 72)
And only fetch records that have an ID of 69 or 72
Edit: In response to your edit ("Its giving me record for both IDs, why is doing so?"), you might want to try using the LIMIT keyword in your Sql. This will only grab the first match and then stop. For example:
SELECT * FROM `jos_menu` WHERE (id = 69 OR id = 72) Limit 1
It will ask TABLE jos_menu for all the records that have an ID of 69 or 72.
Get all the columns from the table called jos_menu
where the id column is equal to 69 or 72.
It lists all the rows from the table jos_menu
where the column named id
has value 69
or 72
So effectively you'll get rows for both id
's
Select all records from jos_menu where ID is either 69 or 72.
Just read it out loud remembering what the wildcards mean.
I'd read this as:
"Select all records from the table 'jos_menu' where the 'id' attribute is equal to 69 or 72"
The Query will return the records from the jos_menu table which satisfy the condtion that id column that is exisiting in jos_menu table having the id's as either 69 or 72.
A bettter way of writing it is
SELECT * FROM jos_menu WHERE id in ( 69 ,72)
here in the above query u can add any number of id's u want..
to limit to only one record
SELECT Top 1 * FROM jos_menu WHERE id in ( 69 ,72)
精彩评论