69
votes
16answers
86k views

mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I am trying to select data from a table but get this error message: mysql_fetch_array() expects parameter 1 to be resource, boolean given.. This is my code: $username = $_POST['username']; ...
20
votes
5answers
4k views

SQL, Auxiliary table of numbers

For certain types of sql queries, an auxiliary table of numbers can be very useful. It may be created as a table with as many rows as you need for a particular task or as a user defined function that ...
71
votes
45answers
10k views

Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc

I've heard that SELECT * is generally bad practice to use when writing SQL commands because it is more efficient to SELECT columns you specifically need. If I need to SELECT every column in a table, ...
75
votes
5answers
6k views

How can an SQL query return data from multiple tables [closed]

I would like to know the following: how to get data from multiple tables in my database? what types of methods are there to do this? what are joins and unions and how are they different from one ...
34
votes
14answers
58k views

Get a list of dates between two dates

Using standard mysql functions is there a way to write a query that will return a list of days between two dates. eg given 2009-01-01 and 2009-01-13 it would return a one column table with the ...
26
votes
5answers
21k views

Remove duplicate rows in MySQL

I have a table with the following fields: id (Unique) url (Unique) title company site_id Now, I need to remove rows having same title, company and site_id. One way to do it will be using the ...
33
votes
3answers
14k views

What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL?

It seems to me that you can do the same thing in a SQL query using either NOT EXISTS, NOT IN, or LEFT JOIN WHERE IS NULL. For example: SELECT a FROM table1 WHERE a NOT IN (SELECT a FROM table2) ...
62
votes
4answers
48k views

SQL Select only rows with Max Value on a Column

I have this table for documents (simplified version here): +------+-------+--------------------------------------+ | id | rev | content | ...
17
votes
11answers
39k views

Search for a string in an all the tables, rows and columns of a SQLL Server DB

I am lost in a big database and I am not able to find where the data I get comes from. I was wondering if it is possible with SQL Server 2005 to search for a string in an all the tables, rows and ...
65
votes
10answers
49k views

Multiple Updates in MySQL

I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL? Edit: For example I have the following Name   id  Col1  Col2Row1 ...
2
votes
1answer
156 views

MySQL Pivot Table Column Data as Rows

I'm struggling to find a solution this MySQL problem. I just can't seem to get my head around how to do it. I have the following tables. Question table +----+-------------+ | id | question | ...
1
vote
5answers
8k views

Simple Query to Grab Max Value for each ID

OK I have a table like this: ID Signal Station OwnerID 111 -120 Home 1 111 -130 Car 1 111 -135 Work 2 222 -98 Home 2 222 ...
29
votes
4answers
8k views

Best way to select random rows PostgreSQL

I saw in a web page the following suggestion for doing a random selection of rows in PostgreSQL: select * from table where random() < 0.01; But some other recommend the following approach: ...
24
votes
13answers
109k views

How can I get column names from a table?

I need to query the database to get the column/field names, not to be confused with data in the table. For example, if I have a table named EVENT_LOG that contains eventID, eventType, eventDesc, and ...
6
votes
13answers
11k views

SQL ORDER BY the 'IN' value list

I have a simple SQL query (in PostgreSQL 8.3) that grabs a bunch of comments. I've composed a bunch of ids before-hand and that gets fed into the WHERE IN clause like so... SELECT * FROM "comments" ...

1 2 3 4 5 58
15 30 50 per page