I am facing issue in figure out the number of rows in mysql table 'users'.
Number of rows when browse the table is different then number of rows when fire SQL query to count(*) from table.
Screenshot :
but when i fire following query
SELECT COUNT(*) FROM `users`
It is giving me different number of rows
Screenshot is of different database, in actual database records are 7,40,215 and in count query it is 16,12,145
Please help me out to figure this issue out.
Related
INSERT cash_transaction2017 SELECT * FROM cash_transaction WHERE created_at < "2018-01-01 00:00:00"
Above is the result from the script I executed, total rows is 336,090.
However, when I browse the table from phpMyAdmin, I can only see 334,473 rows.
After ordering my rows in cash_transaction2017 table in ascending, I found out that some rows are missing because the last created_date is different with that of cash_transaction.
Why is this happening? The result is the same no matter I execute the script from mysql console, or using php codes.
I also tried to use mysqldump with --skip-tz-utc and it's also missing some rows.
UPDATE
SELECT count(*) FROM `cash_transaction2017`
SELECT count(*) FROM `cash_transaction` WHERE created_at < "2018-01-01 00:00:00"
Apparently executing these 2 queries give me same number of rows, however, the last rows from these 2 queries are different. See the screenshots below:
UPDATE 2
Since both tables are transactions table, so if they have the same total amount, it should signifies that they have the same number of rows without any data loss.
So I tried SELECT SUM(amount) on both tables and turns out both the tables have same total amount from SUM(amount)
So the question now is, are there actually any missing rows? Does this problem occur because I'm using innodb?
You may try to add the line in your config.inc.php from your phpMyAdmin directory:
$cfg['MaxExactCount'] = 1000000*
*(Make sure $cfg['MaxExactCount'] is large enough)
This problem probably occurs only with InnoDB tables. Hope this is useful.
How to get duplicate rows containing same string (crn) from a table & crn can contain multiple values too? I got result only for single valued crn.
I wrote a MySQL Query:
SELECT * FROM event_participation
WHERE event_id=15 AND crn IN (SELECT crn FROM event_participation GROUP BY crn HAVING COUNT(*) > 1) ORDER BY crn;
This query can return rows what I expect for but only for single valued crn as shown in second figure.
The first figure shows duplicate rows while fetching all rows from a table but my MySQl query cannot return these duplicate rows containing one of a crn 720286 as in second figure.
Please help me to display those two rows in second figure too.
GitHub Issue: https://github.com/ErSKS/KhEC/issues/10
Im trying to create a table which only will have the serial and 9 int foreign keys.
Is there a way to insert the last id from other tables to this table?
i been trying with RETURNING, nextval()-1, currval(),ordering results by timestamp but nothing seems to work, i just cant get the ids values from the other tables inserted into the table.
even tried this simple set of queries for each table to update one by one of the table columns
$lst="SELECT id from table1 ORDER BY timestamp DESC limit 1";
$lst_res=pg_query($conn,$lst);
$sql_eq_bat_up="UPDATE table9 set table1_id='$lst_res[id]'";
$do_up_tbl1=pg_query($conn,$sql_eq_bat_up);
i been doing some research but had no luck, im using postgreSQL 9.5 and php for this, i hope you can help me thanks.
I have a table bundled among 100 databases in MYSQL (i.e. 1st x rows of the table in database_1, 2nd x rows of the table in database_2, ... , last x rows of the table in database_100)
Each table has a row whenever a user visits a friend for a game.
The columns are iuin, logtime, beuin.
iuin is the user id of the visitor.
beuin is the user id of the friend who was visited.
logtime is when the visit was made.
I would like to find the # of distinct friends who were visited during a week.
There is roughly 300k distinct users who are visited per day.
However, when I extended my code to calculate for a week, I ran out of memory.
My code basically does an SQL query using SELECT DISTINCT beuin for a selected week for the table in each database. I store all the beuin in an array if it's not already stored (so I count distinct friends who were visited), and return the size of the array at the end.
FYI, I can't edit the database around such as joining all the tables in different databases into one table.
Is there any alternative ways i can do this?
Thanks
It's hard to say anything about your without the one. But I think you can solve this problem using mysql. My quick solution:
Create table - CREATE table if not exist users_ids(user_id INT NOT NULL DEAULT 0 PRIMARY KEY(UNIQUE)); in the first db
Truncate users_ids
Run 100 queries like INSERT IGNORE INTO db1.users_ids select distinct user_id from db1.table1;
Select count(*) from users_ids;
SELECT webcal_entry.cal_id, webcal_entry.cal_name , webcal_entry.cal_priority,
webcal_entry.cal_date , webcal_entry.cal_time , webcal_entry_user.cal_status,
webcal_entry.cal_create_by , webcal_entry.cal_access, webcal_entry.cal_duration ,
webcal_entry.cal_description , webcal_entry_user.cal_category
FROM webcal_entry, webcal_entry_user
WHERE webcal_entry.cal_date BETWEEN '20090601' AND '20090631'
When I execute that query php throws back:
mysql_query(): unable to save result set
MySQL client ran out of memory
When I limit the results I see that it is pulling some 2.8 million results back. This table has 7,241 rows.
I realize I could use LIKE, but I really don't want to go that route.
Thanks for any help!
You are joining the webcal_entry and webcal_entry_user tables in your FROM clause but you do not have any JOIN ON or WHERE conditions constraining which rows from webcal_entry_user to return. The result will be the cartesian product of the two tables, which basically means you'll get back each webcal_entry row that has a valid cal_date, multiplied by the number of rows in the webcal_entry_user table.
In other words, if you webcal_entry_user has 400 rows you'll get back 400*7241 = 2.8 million rows! Yikes!
You're doing a cartesian join. Basically, for each row in the first table you're joining against all the rows in the second. If the first table has 4 rows and the second 10 the result set will have 40 (4x10)
You need to add the key you're joining on that exists in both tables to the WHERE clause. Something like:
AND webcal_entry.user_id = webcal_entry_user.user_id